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