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

62 lines
1.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},
Signature, SyntaxShape,
};
2021-09-03 06:01:45 +02:00
use crate::{Alias, Benchmark, BuildString, Def, Do, Each, For, If, Length, Let, LetEnv};
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);
let sig =
Signature::build("where").required("cond", SyntaxShape::RowCondition, "condition");
working_set.add_decl(sig.predeclare());
working_set.add_decl(Box::new(If));
working_set.add_decl(Box::new(Let));
working_set.add_decl(Box::new(LetEnv));
working_set.add_decl(Box::new(Alias));
working_set.add_decl(Box::new(BuildString));
working_set.add_decl(Box::new(Def));
working_set.add_decl(Box::new(For));
2021-09-03 05:45:34 +02:00
working_set.add_decl(Box::new(Each));
2021-09-03 06:01:45 +02:00
working_set.add_decl(Box::new(Do));
2021-09-03 00:58:15 +02:00
working_set.add_decl(Box::new(Benchmark));
2021-09-03 04:15:01 +02:00
working_set.add_decl(Box::new(Length));
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());
working_set.render()
};
{
EngineState::merge_delta(&mut *engine_state.borrow_mut(), delta);
}
engine_state
}