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