1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use nu_engine::{command_prelude::*, get_full_help};

mod add;
mod list;
mod rm;
mod stop;
mod use_;

pub use add::PluginAdd;
pub use list::PluginList;
pub use rm::PluginRm;
pub use stop::PluginStop;
pub use use_::PluginUse;

#[derive(Clone)]
pub struct PluginCommand;

impl Command for PluginCommand {
    fn name(&self) -> &str {
        "plugin"
    }

    fn signature(&self) -> Signature {
        Signature::build("plugin")
            .input_output_types(vec![(Type::Nothing, Type::Nothing)])
            .category(Category::Plugin)
    }

    fn usage(&self) -> &str {
        "Commands for managing plugins."
    }

    fn run(
        &self,
        engine_state: &EngineState,
        stack: &mut Stack,
        call: &Call,
        _input: PipelineData,
    ) -> Result<PipelineData, ShellError> {
        Ok(Value::string(get_full_help(self, engine_state, stack), call.head).into_pipeline_data())
    }

    fn examples(&self) -> Vec<Example> {
        vec![
            Example {
                example: "plugin add nu_plugin_inc",
                description: "Run the `nu_plugin_inc` plugin from the current directory and install its signatures.",
                result: None,
            },
            Example {
                example: "plugin use inc",
                description: "
Load (or reload) the `inc` plugin from the plugin registry file and put its
commands in scope. The plugin must already be in the registry file at parse
time.
"
                .trim(),
                result: None,
            },
            Example {
                example: "plugin list",
                description: "List installed plugins",
                result: None,
            },
            Example {
                example: "plugin stop inc",
                description: "Stop the plugin named `inc`.",
                result: None,
            },
            Example {
                example: "plugin rm inc",
                description: "Remove the installed signatures for the `inc` plugin.",
                result: None,
            },
        ]
    }
}