Skip to main content

nu_cmd_plugin/commands/plugin/
mod.rs

1use nu_engine::{command_prelude::*, get_full_help};
2
3mod add;
4mod list;
5mod rm;
6mod stop;
7mod use_;
8
9pub use add::PluginAdd;
10pub use list::PluginList;
11pub use rm::PluginRm;
12pub use stop::PluginStop;
13pub use use_::PluginUse;
14
15#[derive(Clone)]
16pub struct PluginCommand;
17
18impl Command for PluginCommand {
19    fn name(&self) -> &str {
20        "plugin"
21    }
22
23    fn signature(&self) -> Signature {
24        Signature::build("plugin")
25            .input_output_types(vec![(Type::Nothing, Type::Nothing)])
26            .category(Category::Plugin)
27    }
28
29    fn description(&self) -> &str {
30        "Commands for managing plugins."
31    }
32
33    fn run(
34        &self,
35        engine_state: &EngineState,
36        stack: &mut Stack,
37        call: &Call,
38        _input: PipelineData,
39    ) -> Result<PipelineData, ShellError> {
40        Ok(Value::string(
41            get_full_help(self, engine_state, stack, call.head),
42            call.head,
43        )
44        .into_pipeline_data())
45    }
46
47    fn examples(&self) -> Vec<Example<'_>> {
48        vec![
49            Example {
50                example: "plugin add nu_plugin_inc",
51                description: "Run the `nu_plugin_inc` plugin from the current directory and install its signatures.",
52                result: None,
53            },
54            Example {
55                example: "plugin use inc",
56                description: "
57Load (or reload) the `inc` plugin from the plugin registry file and put its
58commands in scope. The plugin must already be in the registry file at parse
59time.
60"
61                .trim(),
62                result: None,
63            },
64            Example {
65                example: "plugin list",
66                description: "List installed plugins",
67                result: None,
68            },
69            Example {
70                example: "plugin stop inc",
71                description: "Stop the plugin named `inc`.",
72                result: None,
73            },
74            Example {
75                example: "plugin rm inc",
76                description: "Remove the installed signatures for the `inc` plugin.",
77                result: None,
78            },
79        ]
80    }
81}