nu_cli/commands/
default_context.rs

1use crate::commands::*;
2use nu_protocol::engine::{EngineState, StateWorkingSet};
3
4pub fn add_cli_context(mut engine_state: EngineState) -> EngineState {
5    let delta = {
6        let mut working_set = StateWorkingSet::new(&engine_state);
7
8        macro_rules! bind_command {
9            ( $( $command:expr ),* $(,)? ) => {
10                $( working_set.add_decl(Box::new($command)); )*
11            };
12        }
13
14        bind_command! {
15            Commandline,
16            CommandlineEdit,
17            CommandlineGetCursor,
18            CommandlineSetCursor,
19            History,
20            Keybindings,
21            KeybindingsDefault,
22            KeybindingsList,
23            KeybindingsListen,
24        };
25
26        #[cfg(feature = "sqlite")]
27        bind_command! {
28            HistoryImport,
29            HistorySession
30        };
31
32        working_set.render()
33    };
34
35    if let Err(err) = engine_state.merge_delta(delta) {
36        eprintln!("Error creating CLI command context: {err:?}");
37    }
38
39    engine_state
40}