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-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,
|
|
|
|
Cp,
|
|
|
|
Def,
|
|
|
|
Do,
|
|
|
|
Each,
|
|
|
|
ExportDef,
|
|
|
|
External,
|
|
|
|
For,
|
|
|
|
From,
|
|
|
|
FromJson,
|
|
|
|
Get,
|
|
|
|
Griddle,
|
|
|
|
Help,
|
|
|
|
Hide,
|
|
|
|
If,
|
2021-10-11 01:57:39 +00:00
|
|
|
Into,
|
|
|
|
IntoBinary,
|
|
|
|
IntoFilesize,
|
|
|
|
IntoInt,
|
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-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,
|
|
|
|
Rm,
|
|
|
|
Select,
|
2021-10-12 21:55:29 +00:00
|
|
|
Size,
|
2021-10-10 20:24:54 +00:00
|
|
|
Split,
|
|
|
|
SplitChars,
|
|
|
|
SplitColumn,
|
|
|
|
SplitRow,
|
|
|
|
Sys,
|
|
|
|
Table,
|
|
|
|
Touch,
|
|
|
|
Use,
|
|
|
|
Where,
|
|
|
|
Wrap
|
|
|
|
);
|
2021-09-03 02:15:01 +00:00
|
|
|
|
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());
|
|
|
|
let sig = Signature::build("vars");
|
|
|
|
working_set.add_decl(sig.predeclare());
|
|
|
|
let sig = Signature::build("decls");
|
|
|
|
working_set.add_decl(sig.predeclare());
|
|
|
|
let sig = Signature::build("blocks");
|
|
|
|
working_set.add_decl(sig.predeclare());
|
|
|
|
let sig = Signature::build("stack");
|
|
|
|
working_set.add_decl(sig.predeclare());
|
2021-09-25 16:28:15 +00:00
|
|
|
let sig = Signature::build("contents");
|
|
|
|
working_set.add_decl(sig.predeclare());
|
2021-09-02 22:58:15 +00:00
|
|
|
|
|
|
|
working_set.render()
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
2021-10-25 06:31:39 +00:00
|
|
|
EngineState::merge_delta(&mut engine_state, delta);
|
2021-09-02 22:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
engine_state
|
|
|
|
}
|