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);
|
|
|
|
|
2021-10-10 06:13:15 +02:00
|
|
|
macro_rules! bind_command {
|
|
|
|
( $command:expr ) => {
|
|
|
|
working_set.add_decl(Box::new($command));
|
|
|
|
};
|
|
|
|
( $( $command:expr ),* ) => {
|
|
|
|
$( working_set.add_decl(Box::new($command)); )*
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: sort items categorically
|
|
|
|
#[rustfmt::skip] bind_command!( Alias, Benchmark, BuildString,
|
|
|
|
Cd, Cp, Def, Do, Each, ExportDef, External, For, From,
|
|
|
|
FromJson, Get, Griddle, Help, Hide, If, Length, Let, LetEnv,
|
|
|
|
Lines, Ls, Mkdir, Module, Mv, Open, Ps, Rm, Save, Select,
|
|
|
|
Split, SplitChars, SplitColumn, SplitRow, Sys, Table, Touch,
|
|
|
|
Use, Where, Wrap );
|
2021-09-23 21:03:08 +02:00
|
|
|
|
2021-09-14 06:59:46 +02:00
|
|
|
// This is a WIP proof of concept
|
2021-10-10 06:13:15 +02:00
|
|
|
bind_command!(ListGitBranches, Git, GitCheckout, Source);
|
2021-09-11 06:54:24 +02:00
|
|
|
|
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
|
|
|
|
}
|