nushell/crates/nu-command/src/default_context.rs

77 lines
2.7 KiB
Rust
Raw Normal View History

2021-09-03 00:58:15 +02:00
use std::{cell::RefCell, rc::Rc};
use nu_protocol::{
engine::{EngineState, StateWorkingSet},
2021-10-01 23:53:13 +02:00
Signature,
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
pub fn create_default_context() -> Rc<RefCell<EngineState>> {
let engine_state = Rc::new(RefCell::new(EngineState::new()));
let delta = {
let engine_state = engine_state.borrow();
let mut working_set = StateWorkingSet::new(&*engine_state);
working_set.add_decl(Box::new(Alias));
2021-10-01 07:11:49 +02:00
working_set.add_decl(Box::new(Benchmark));
2021-09-03 00:58:15 +02:00
working_set.add_decl(Box::new(BuildString));
2021-10-02 22:16:37 +02:00
working_set.add_decl(Box::new(Cd));
2021-10-05 21:55:46 +02:00
working_set.add_decl(Box::new(Cp));
2021-09-03 00:58:15 +02:00
working_set.add_decl(Box::new(Def));
2021-09-03 06:01:45 +02:00
working_set.add_decl(Box::new(Do));
2021-10-01 07:11:49 +02:00
working_set.add_decl(Box::new(Each));
2021-09-28 20:03:53 +02:00
working_set.add_decl(Box::new(ExportDef));
2021-10-01 07:11:49 +02:00
working_set.add_decl(Box::new(External));
working_set.add_decl(Box::new(For));
working_set.add_decl(Box::new(From));
working_set.add_decl(Box::new(FromJson));
2021-10-02 04:59:11 +02:00
working_set.add_decl(Box::new(Get));
2021-10-01 23:53:13 +02:00
working_set.add_decl(Box::new(Help));
working_set.add_decl(Box::new(Hide));
2021-10-01 07:11:49 +02:00
working_set.add_decl(Box::new(If));
2021-09-03 04:15:01 +02:00
working_set.add_decl(Box::new(Length));
2021-10-01 07:11:49 +02:00
working_set.add_decl(Box::new(Let));
working_set.add_decl(Box::new(LetEnv));
working_set.add_decl(Box::new(Lines));
2021-09-10 03:06:44 +02:00
working_set.add_decl(Box::new(Ls));
2021-09-26 00:59:18 +02:00
working_set.add_decl(Box::new(Module));
2021-10-04 13:32:08 +02:00
working_set.add_decl(Box::new(Mv));
2021-10-01 23:53:13 +02:00
working_set.add_decl(Box::new(Ps));
2021-10-02 06:55:05 +02:00
working_set.add_decl(Box::new(Select));
2021-10-01 08:53:47 +02:00
working_set.add_decl(Box::new(Sys));
2021-09-10 04:27:12 +02:00
working_set.add_decl(Box::new(Table));
2021-10-01 07:11:49 +02:00
working_set.add_decl(Box::new(Use));
working_set.add_decl(Box::new(Where));
2021-10-02 04:59:11 +02:00
working_set.add_decl(Box::new(Wrap));
2021-09-23 21:03:08 +02:00
// This is a WIP proof of concept
working_set.add_decl(Box::new(ListGitBranches));
working_set.add_decl(Box::new(Git));
working_set.add_decl(Box::new(GitCheckout));
2021-09-03 04:15:01 +02:00
2021-09-11 06:54:24 +02:00
working_set.add_decl(Box::new(Source));
2021-09-03 00:58:15 +02: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 18:28:15 +02:00
let sig = Signature::build("contents");
working_set.add_decl(sig.predeclare());
2021-09-03 00:58:15 +02:00
working_set.render()
};
{
EngineState::merge_delta(&mut *engine_state.borrow_mut(), delta);
}
engine_state
}