Skip to main content

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            Abbreviations,
16            AbbreviationsList,
17            Commandline,
18            CommandlineEdit,
19            CommandlineGetCursor,
20            CommandlineSetCursor,
21            History,
22            Keybindings,
23            KeybindingsDefault,
24            KeybindingsList,
25            KeybindingsListen,
26        };
27
28        #[cfg(feature = "sqlite")]
29        bind_command! {
30            HistoryImport,
31            HistorySession
32        };
33
34        working_set.render()
35    };
36
37    if let Err(err) = engine_state.merge_delta(delta) {
38        eprintln!("Error creating CLI command context: {err:?}");
39    }
40
41    engine_state
42}