2021-11-26 08:00:57 +00:00
|
|
|
use nu_protocol::engine::{EngineState, StateWorkingSet};
|
2021-09-02 22:58:15 +00:00
|
|
|
|
2021-10-02 02:59:11 +00:00
|
|
|
use crate::*;
|
2021-09-02 22:58:15 +00:00
|
|
|
|
2021-10-25 06:31:39 +00:00
|
|
|
pub fn create_default_context() -> EngineState {
|
|
|
|
let mut engine_state = EngineState::new();
|
2021-10-28 04:13:10 +00:00
|
|
|
|
2021-09-02 22:58:15 +00:00
|
|
|
let delta = {
|
2021-10-25 06:31:39 +00:00
|
|
|
let mut working_set = StateWorkingSet::new(&engine_state);
|
2021-09-02 22:58:15 +00:00
|
|
|
|
2021-10-10 04:13:15 +00: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 19:03:08 +00:00
|
|
|
|
2021-11-28 19:35:02 +00: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")]
|
2021-12-06 04:09:49 +00:00
|
|
|
add_dataframe_decls(&mut working_set);
|
2021-11-28 19:35:02 +00:00
|
|
|
|
2021-10-12 17:44:23 +00:00
|
|
|
// TODO: sort default context items categorically
|
2021-10-10 20:24:54 +00:00
|
|
|
bind_command!(
|
|
|
|
Alias,
|
2021-11-27 17:49:03 +00:00
|
|
|
All,
|
2021-11-28 08:29:35 +00:00
|
|
|
Any,
|
2021-11-18 19:16:04 +00:00
|
|
|
Append,
|
2021-10-10 20:24:54 +00:00
|
|
|
Benchmark,
|
|
|
|
BuildString,
|
2021-12-04 17:15:03 +00:00
|
|
|
Cal,
|
2021-10-10 20:24:54 +00:00
|
|
|
Cd,
|
2021-11-28 08:32:44 +00:00
|
|
|
Clear,
|
2021-11-08 06:21:24 +00:00
|
|
|
Collect,
|
2021-10-10 20:24:54 +00:00
|
|
|
Cp,
|
2021-10-31 06:54:51 +00:00
|
|
|
Date,
|
|
|
|
DateFormat,
|
|
|
|
DateHumanize,
|
|
|
|
DateListTimezones,
|
|
|
|
DateNow,
|
|
|
|
DateToTable,
|
|
|
|
DateToTimezone,
|
2021-11-19 05:00:29 +00:00
|
|
|
Debug,
|
2021-10-10 20:24:54 +00:00
|
|
|
Def,
|
2021-11-19 05:00:29 +00:00
|
|
|
Describe,
|
2021-10-10 20:24:54 +00:00
|
|
|
Do,
|
2021-11-21 19:04:20 +00:00
|
|
|
Drop,
|
2021-10-10 20:24:54 +00:00
|
|
|
Each,
|
2021-11-01 08:12:48 +00:00
|
|
|
Echo,
|
2021-11-26 08:00:57 +00:00
|
|
|
Exit,
|
2021-11-15 23:16:06 +00:00
|
|
|
ExportCommand,
|
2021-10-10 20:24:54 +00:00
|
|
|
ExportDef,
|
2021-11-15 23:16:06 +00:00
|
|
|
ExportEnv,
|
2021-10-10 20:24:54 +00:00
|
|
|
External,
|
2021-10-31 21:53:37 +00:00
|
|
|
First,
|
2021-10-10 20:24:54 +00:00
|
|
|
For,
|
2021-11-02 17:13:06 +00:00
|
|
|
Format,
|
2021-10-10 20:24:54 +00:00
|
|
|
From,
|
2021-11-09 20:17:37 +00:00
|
|
|
FromCsv,
|
2021-10-10 20:24:54 +00:00
|
|
|
FromJson,
|
2021-11-10 01:02:33 +00:00
|
|
|
FromYaml,
|
|
|
|
FromYml,
|
2021-11-09 20:17:37 +00:00
|
|
|
FromTsv,
|
2021-11-19 19:23:35 +00:00
|
|
|
FromToml,
|
2021-11-12 20:46:39 +00:00
|
|
|
FromUrl,
|
|
|
|
FromEml,
|
2021-11-19 19:23:35 +00:00
|
|
|
FromOds,
|
2021-11-25 17:10:56 +00:00
|
|
|
FromIcs,
|
|
|
|
FromIni,
|
|
|
|
FromVcf,
|
2021-11-29 19:22:13 +00:00
|
|
|
FromSsv,
|
|
|
|
FromXml,
|
2021-11-19 19:23:35 +00:00
|
|
|
FromXlsx,
|
2021-10-10 20:24:54 +00:00
|
|
|
Get,
|
|
|
|
Griddle,
|
|
|
|
Help,
|
|
|
|
Hide,
|
|
|
|
If,
|
2021-10-11 01:57:39 +00:00
|
|
|
Into,
|
|
|
|
IntoBinary,
|
2021-12-04 03:41:02 +00:00
|
|
|
IntoDatetime,
|
2021-12-03 02:01:19 +00:00
|
|
|
IntoDecimal,
|
2021-10-11 01:57:39 +00:00
|
|
|
IntoFilesize,
|
|
|
|
IntoInt,
|
2021-11-02 19:39:16 +00:00
|
|
|
IntoString,
|
2021-11-29 18:21:55 +00:00
|
|
|
Kill,
|
2021-10-26 18:29:00 +00:00
|
|
|
Last,
|
2021-10-10 20:24:54 +00:00
|
|
|
Length,
|
|
|
|
Let,
|
|
|
|
LetEnv,
|
|
|
|
Lines,
|
|
|
|
Ls,
|
2021-10-24 23:58:18 +00:00
|
|
|
Math,
|
|
|
|
MathAbs,
|
2021-10-27 01:00:50 +00:00
|
|
|
MathAvg,
|
2021-11-03 11:59:08 +00:00
|
|
|
MathCeil,
|
2021-11-03 00:17:27 +00:00
|
|
|
MathFloor,
|
2021-11-05 17:58:40 +00:00
|
|
|
MathEval,
|
2021-10-29 19:02:42 +00:00
|
|
|
MathMax,
|
2021-11-03 21:24:15 +00:00
|
|
|
MathMedian,
|
2021-10-29 19:02:42 +00:00
|
|
|
MathMin,
|
2021-11-03 21:24:15 +00:00
|
|
|
MathMode,
|
2021-11-01 21:29:34 +00:00
|
|
|
MathProduct,
|
|
|
|
MathRound,
|
|
|
|
MathSqrt,
|
2021-11-05 17:58:40 +00:00
|
|
|
MathStddev,
|
2021-11-01 21:29:34 +00:00
|
|
|
MathSum,
|
2021-11-05 17:58:40 +00:00
|
|
|
MathVariance,
|
2021-10-10 20:24:54 +00:00
|
|
|
Mkdir,
|
|
|
|
Module,
|
|
|
|
Mv,
|
2021-12-10 00:16:04 +00:00
|
|
|
Nth,
|
2021-10-26 01:30:53 +00:00
|
|
|
ParEach,
|
2021-11-15 18:27:15 +00:00
|
|
|
Parse,
|
2021-12-07 08:46:21 +00:00
|
|
|
Prepend,
|
2021-10-10 20:24:54 +00:00
|
|
|
Ps,
|
2021-10-30 17:51:20 +00:00
|
|
|
Range,
|
2021-11-30 06:12:19 +00:00
|
|
|
Random,
|
2021-12-05 03:09:45 +00:00
|
|
|
Reject,
|
2021-11-07 18:18:27 +00:00
|
|
|
Reverse,
|
2021-10-10 20:24:54 +00:00
|
|
|
Rm,
|
|
|
|
Select,
|
2021-11-07 01:19:57 +00:00
|
|
|
Shuffle,
|
2021-10-12 21:55:29 +00:00
|
|
|
Size,
|
2021-11-29 06:52:23 +00:00
|
|
|
Skip,
|
|
|
|
SkipUntil,
|
|
|
|
SkipWhile,
|
2021-11-28 21:15:32 +00:00
|
|
|
Sleep,
|
2021-11-26 08:00:57 +00:00
|
|
|
Source,
|
2021-10-10 20:24:54 +00:00
|
|
|
Split,
|
|
|
|
SplitChars,
|
|
|
|
SplitColumn,
|
|
|
|
SplitRow,
|
2021-11-09 01:59:44 +00:00
|
|
|
Str,
|
|
|
|
StrCamelCase,
|
2021-11-09 07:40:56 +00:00
|
|
|
StrCapitalize,
|
2021-11-09 01:59:44 +00:00
|
|
|
StrCollect,
|
2021-11-09 20:16:53 +00:00
|
|
|
StrContains,
|
|
|
|
StrDowncase,
|
2021-11-10 00:51:55 +00:00
|
|
|
StrEndswith,
|
2021-11-11 19:45:39 +00:00
|
|
|
StrIndexOf,
|
2021-11-13 21:25:55 +00:00
|
|
|
StrLength,
|
2021-11-10 23:11:34 +00:00
|
|
|
StrFindReplace,
|
2021-11-09 01:59:44 +00:00
|
|
|
StrKebabCase,
|
|
|
|
StrPascalCase,
|
|
|
|
StrScreamingSnakeCase,
|
|
|
|
StrSnakeCase,
|
2021-11-14 19:36:24 +00:00
|
|
|
StrLpad,
|
|
|
|
StrRpad,
|
2021-11-15 23:16:56 +00:00
|
|
|
StrStartsWith,
|
2021-11-15 01:43:40 +00:00
|
|
|
StrReverse,
|
2021-12-01 06:42:57 +00:00
|
|
|
StrSubstring,
|
2021-12-03 02:00:32 +00:00
|
|
|
StrUpcase,
|
2021-12-02 04:38:44 +00:00
|
|
|
StrTrim,
|
2021-10-10 20:24:54 +00:00
|
|
|
Sys,
|
|
|
|
Table,
|
2021-10-29 06:26:29 +00:00
|
|
|
To,
|
|
|
|
ToJson,
|
2021-12-02 04:38:00 +00:00
|
|
|
ToUrl,
|
|
|
|
ToToml,
|
2021-12-03 02:02:22 +00:00
|
|
|
ToTsv,
|
|
|
|
ToCsv,
|
2021-10-10 20:24:54 +00:00
|
|
|
Touch,
|
2021-12-07 08:47:48 +00:00
|
|
|
Uniq,
|
2021-10-10 20:24:54 +00:00
|
|
|
Use,
|
2021-11-13 23:02:54 +00:00
|
|
|
Update,
|
2021-10-10 20:24:54 +00:00
|
|
|
Where,
|
2021-11-04 02:32:35 +00:00
|
|
|
WithEnv,
|
2021-11-02 05:28:28 +00:00
|
|
|
Wrap,
|
|
|
|
Zip
|
2021-10-10 20:24:54 +00:00
|
|
|
);
|
2021-09-03 02:15:01 +00:00
|
|
|
|
2021-11-02 20:56:00 +00:00
|
|
|
#[cfg(feature = "plugin")]
|
|
|
|
bind_command!(Register);
|
|
|
|
|
2021-09-14 04:59:46 +00:00
|
|
|
// This is a WIP proof of concept
|
2021-11-26 08:00:57 +00:00
|
|
|
// bind_command!(ListGitBranches, Git, GitCheckout, Source);
|
2021-09-02 22:58:15 +00:00
|
|
|
|
|
|
|
working_set.render()
|
|
|
|
};
|
|
|
|
|
2021-11-19 02:51:42 +00:00
|
|
|
let _ = engine_state.merge_delta(delta);
|
2021-09-02 22:58:15 +00:00
|
|
|
|
|
|
|
engine_state
|
|
|
|
}
|