2021-11-26 09:00:57 +01:00
|
|
|
use nu_protocol::engine::{EngineState, StateWorkingSet};
|
2021-09-03 00:58:15 +02:00
|
|
|
|
2021-10-02 04:59:11 +02:00
|
|
|
use crate::*;
|
2021-09-03 00:58:15 +02:00
|
|
|
|
2021-10-25 08:31:39 +02:00
|
|
|
pub fn create_default_context() -> EngineState {
|
|
|
|
let mut engine_state = EngineState::new();
|
2021-10-28 06:13:10 +02:00
|
|
|
|
2021-09-03 00:58:15 +02:00
|
|
|
let delta = {
|
2021-10-25 08:31:39 +02:00
|
|
|
let mut working_set = StateWorkingSet::new(&engine_state);
|
2021-09-03 00:58:15 +02:00
|
|
|
|
2021-10-10 06:13:15 +02:00
|
|
|
macro_rules! bind_command {
|
|
|
|
( $command:expr ) => {
|
|
|
|
working_set.add_decl(Box::new($command));
|
|
|
|
};
|
|
|
|
( $( $command:expr ),* ) => {
|
|
|
|
$( working_set.add_decl(Box::new($command)); )*
|
|
|
|
};
|
|
|
|
}
|
2021-09-23 21:03:08 +02:00
|
|
|
|
2021-11-28 20:35:02 +01:00
|
|
|
// If there are commands that have the same name as default declarations,
|
|
|
|
// they have to be registered before the main declarations. This helps to make
|
|
|
|
// them only accessible if the correct input value category is used with the
|
|
|
|
// declaration
|
|
|
|
#[cfg(feature = "dataframe")]
|
|
|
|
bind_command!(DataTypes, DescribeDF, OpenDataFrame, ToDataFrame);
|
|
|
|
|
2021-10-12 19:44:23 +02:00
|
|
|
// TODO: sort default context items categorically
|
2021-10-10 22:24:54 +02:00
|
|
|
bind_command!(
|
|
|
|
Alias,
|
2021-11-27 18:49:03 +01:00
|
|
|
All,
|
2021-11-28 09:29:35 +01:00
|
|
|
Any,
|
2021-11-18 20:16:04 +01:00
|
|
|
Append,
|
2021-10-10 22:24:54 +02:00
|
|
|
Benchmark,
|
|
|
|
BuildString,
|
|
|
|
Cd,
|
2021-11-28 09:32:44 +01:00
|
|
|
Clear,
|
2021-11-08 07:21:24 +01:00
|
|
|
Collect,
|
2021-10-10 22:24:54 +02:00
|
|
|
Cp,
|
2021-10-31 07:54:51 +01:00
|
|
|
Date,
|
|
|
|
DateFormat,
|
|
|
|
DateHumanize,
|
|
|
|
DateListTimezones,
|
|
|
|
DateNow,
|
|
|
|
DateToTable,
|
|
|
|
DateToTimezone,
|
2021-11-19 06:00:29 +01:00
|
|
|
Debug,
|
2021-10-10 22:24:54 +02:00
|
|
|
Def,
|
2021-11-19 06:00:29 +01:00
|
|
|
Describe,
|
2021-10-10 22:24:54 +02:00
|
|
|
Do,
|
2021-11-21 20:04:20 +01:00
|
|
|
Drop,
|
2021-10-10 22:24:54 +02:00
|
|
|
Each,
|
2021-11-01 09:12:48 +01:00
|
|
|
Echo,
|
2021-11-26 09:00:57 +01:00
|
|
|
Exit,
|
2021-11-16 00:16:06 +01:00
|
|
|
ExportCommand,
|
2021-10-10 22:24:54 +02:00
|
|
|
ExportDef,
|
2021-11-16 00:16:06 +01:00
|
|
|
ExportEnv,
|
2021-10-10 22:24:54 +02:00
|
|
|
External,
|
2021-10-31 22:53:37 +01:00
|
|
|
First,
|
2021-10-10 22:24:54 +02:00
|
|
|
For,
|
2021-11-02 18:13:06 +01:00
|
|
|
Format,
|
2021-10-10 22:24:54 +02:00
|
|
|
From,
|
2021-11-09 21:17:37 +01:00
|
|
|
FromCsv,
|
2021-10-10 22:24:54 +02:00
|
|
|
FromJson,
|
2021-11-10 02:02:33 +01:00
|
|
|
FromYaml,
|
|
|
|
FromYml,
|
2021-11-09 21:17:37 +01:00
|
|
|
FromTsv,
|
2021-11-19 20:23:35 +01:00
|
|
|
FromToml,
|
2021-11-12 21:46:39 +01:00
|
|
|
FromUrl,
|
|
|
|
FromEml,
|
2021-11-19 20:23:35 +01:00
|
|
|
FromOds,
|
2021-11-25 18:10:56 +01:00
|
|
|
FromIcs,
|
|
|
|
FromIni,
|
|
|
|
FromVcf,
|
2021-11-29 20:22:13 +01:00
|
|
|
FromSsv,
|
|
|
|
FromXml,
|
2021-11-19 20:23:35 +01:00
|
|
|
FromXlsx,
|
2021-10-10 22:24:54 +02:00
|
|
|
Get,
|
|
|
|
Griddle,
|
|
|
|
Help,
|
|
|
|
Hide,
|
|
|
|
If,
|
2021-10-11 03:57:39 +02:00
|
|
|
Into,
|
|
|
|
IntoBinary,
|
|
|
|
IntoFilesize,
|
|
|
|
IntoInt,
|
2021-11-02 20:39:16 +01:00
|
|
|
IntoString,
|
2021-11-29 19:21:55 +01:00
|
|
|
Kill,
|
2021-10-26 20:29:00 +02:00
|
|
|
Last,
|
2021-10-10 22:24:54 +02:00
|
|
|
Length,
|
|
|
|
Let,
|
|
|
|
LetEnv,
|
|
|
|
Lines,
|
|
|
|
Ls,
|
2021-10-25 01:58:18 +02:00
|
|
|
Math,
|
|
|
|
MathAbs,
|
2021-10-27 03:00:50 +02:00
|
|
|
MathAvg,
|
2021-11-03 12:59:08 +01:00
|
|
|
MathCeil,
|
2021-11-03 01:17:27 +01:00
|
|
|
MathFloor,
|
2021-11-05 18:58:40 +01:00
|
|
|
MathEval,
|
2021-10-29 21:02:42 +02:00
|
|
|
MathMax,
|
2021-11-03 22:24:15 +01:00
|
|
|
MathMedian,
|
2021-10-29 21:02:42 +02:00
|
|
|
MathMin,
|
2021-11-03 22:24:15 +01:00
|
|
|
MathMode,
|
2021-11-01 22:29:34 +01:00
|
|
|
MathProduct,
|
|
|
|
MathRound,
|
|
|
|
MathSqrt,
|
2021-11-05 18:58:40 +01:00
|
|
|
MathStddev,
|
2021-11-01 22:29:34 +01:00
|
|
|
MathSum,
|
2021-11-05 18:58:40 +01:00
|
|
|
MathVariance,
|
2021-10-10 22:24:54 +02:00
|
|
|
Mkdir,
|
|
|
|
Module,
|
|
|
|
Mv,
|
2021-10-26 03:30:53 +02:00
|
|
|
ParEach,
|
2021-11-15 19:27:15 +01:00
|
|
|
Parse,
|
2021-10-10 22:24:54 +02:00
|
|
|
Ps,
|
2021-10-30 19:51:20 +02:00
|
|
|
Range,
|
2021-11-30 07:12:19 +01:00
|
|
|
Random,
|
2021-11-07 19:18:27 +01:00
|
|
|
Reverse,
|
2021-10-10 22:24:54 +02:00
|
|
|
Rm,
|
|
|
|
Select,
|
2021-11-07 02:19:57 +01:00
|
|
|
Shuffle,
|
2021-10-12 23:55:29 +02:00
|
|
|
Size,
|
2021-11-29 07:52:23 +01:00
|
|
|
Skip,
|
|
|
|
SkipUntil,
|
|
|
|
SkipWhile,
|
2021-11-28 22:15:32 +01:00
|
|
|
Sleep,
|
2021-11-26 09:00:57 +01:00
|
|
|
Source,
|
2021-10-10 22:24:54 +02:00
|
|
|
Split,
|
|
|
|
SplitChars,
|
|
|
|
SplitColumn,
|
|
|
|
SplitRow,
|
2021-11-09 02:59:44 +01:00
|
|
|
Str,
|
|
|
|
StrCamelCase,
|
2021-11-09 08:40:56 +01:00
|
|
|
StrCapitalize,
|
2021-11-09 02:59:44 +01:00
|
|
|
StrCollect,
|
2021-11-09 21:16:53 +01:00
|
|
|
StrContains,
|
|
|
|
StrDowncase,
|
2021-11-10 01:51:55 +01:00
|
|
|
StrEndswith,
|
2021-11-11 20:45:39 +01:00
|
|
|
StrIndexOf,
|
2021-11-13 22:25:55 +01:00
|
|
|
StrLength,
|
2021-11-11 00:11:34 +01:00
|
|
|
StrFindReplace,
|
2021-11-09 02:59:44 +01:00
|
|
|
StrKebabCase,
|
|
|
|
StrPascalCase,
|
|
|
|
StrScreamingSnakeCase,
|
|
|
|
StrSnakeCase,
|
2021-11-14 20:36:24 +01:00
|
|
|
StrLpad,
|
|
|
|
StrRpad,
|
2021-11-16 00:16:56 +01:00
|
|
|
StrStartsWith,
|
2021-11-15 02:43:40 +01:00
|
|
|
StrReverse,
|
2021-10-10 22:24:54 +02:00
|
|
|
Sys,
|
|
|
|
Table,
|
2021-10-29 08:26:29 +02:00
|
|
|
To,
|
|
|
|
ToJson,
|
2021-10-10 22:24:54 +02:00
|
|
|
Touch,
|
|
|
|
Use,
|
2021-11-14 00:02:54 +01:00
|
|
|
Update,
|
2021-10-10 22:24:54 +02:00
|
|
|
Where,
|
2021-11-04 03:32:35 +01:00
|
|
|
WithEnv,
|
2021-11-02 06:28:28 +01:00
|
|
|
Wrap,
|
|
|
|
Zip
|
2021-10-10 22:24:54 +02:00
|
|
|
);
|
2021-09-03 04:15:01 +02:00
|
|
|
|
2021-11-02 21:56:00 +01:00
|
|
|
#[cfg(feature = "plugin")]
|
|
|
|
bind_command!(Register);
|
|
|
|
|
2021-09-14 06:59:46 +02:00
|
|
|
// This is a WIP proof of concept
|
2021-11-26 09:00:57 +01:00
|
|
|
// bind_command!(ListGitBranches, Git, GitCheckout, Source);
|
2021-09-03 00:58:15 +02:00
|
|
|
|
|
|
|
working_set.render()
|
|
|
|
};
|
|
|
|
|
2021-11-19 03:51:42 +01:00
|
|
|
let _ = engine_state.merge_delta(delta);
|
2021-09-03 00:58:15 +02:00
|
|
|
|
|
|
|
engine_state
|
|
|
|
}
|