2021-09-02 22:58:15 +00:00
|
|
|
use nu_protocol::{
|
|
|
|
engine::{EngineState, StateWorkingSet},
|
2021-10-01 21:53:13 +00:00
|
|
|
Signature,
|
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-10-12 17:44:23 +00:00
|
|
|
// TODO: sort default context items categorically
|
2021-10-10 20:24:54 +00:00
|
|
|
bind_command!(
|
|
|
|
Alias,
|
|
|
|
Benchmark,
|
|
|
|
BuildString,
|
|
|
|
Cd,
|
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-10-10 20:24:54 +00:00
|
|
|
Def,
|
|
|
|
Do,
|
|
|
|
Each,
|
2021-11-01 08:12:48 +00:00
|
|
|
Echo,
|
2021-10-10 20:24:54 +00:00
|
|
|
ExportDef,
|
|
|
|
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-09 20:17:37 +00:00
|
|
|
FromTsv,
|
2021-10-10 20:24:54 +00:00
|
|
|
Get,
|
|
|
|
Griddle,
|
|
|
|
Help,
|
|
|
|
Hide,
|
|
|
|
If,
|
2021-10-11 01:57:39 +00:00
|
|
|
Into,
|
|
|
|
IntoBinary,
|
|
|
|
IntoFilesize,
|
|
|
|
IntoInt,
|
2021-11-02 19:39:16 +00:00
|
|
|
IntoString,
|
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-10-26 01:30:53 +00:00
|
|
|
ParEach,
|
2021-10-10 20:24:54 +00:00
|
|
|
Ps,
|
2021-10-30 17:51:20 +00:00
|
|
|
Range,
|
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-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-09 01:59:44 +00:00
|
|
|
StrKebabCase,
|
|
|
|
StrPascalCase,
|
|
|
|
StrScreamingSnakeCase,
|
|
|
|
StrSnakeCase,
|
2021-10-10 20:24:54 +00:00
|
|
|
Sys,
|
|
|
|
Table,
|
2021-10-29 06:26:29 +00:00
|
|
|
To,
|
|
|
|
ToJson,
|
2021-10-10 20:24:54 +00:00
|
|
|
Touch,
|
|
|
|
Use,
|
|
|
|
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-10-10 04:13:15 +00:00
|
|
|
bind_command!(ListGitBranches, Git, GitCheckout, Source);
|
2021-09-11 04:54:24 +00:00
|
|
|
|
2021-09-02 22:58:15 +00:00
|
|
|
let sig = Signature::build("exit");
|
|
|
|
working_set.add_decl(sig.predeclare());
|
|
|
|
|
|
|
|
working_set.render()
|
|
|
|
};
|
|
|
|
|
2021-11-02 19:53:48 +00:00
|
|
|
engine_state.merge_delta(delta);
|
2021-09-02 22:58:15 +00:00
|
|
|
|
|
|
|
engine_state
|
|
|
|
}
|