nu_cmd_plugin/commands/plugin/
use_.rs1use nu_engine::command_prelude::*;
2use nu_protocol::engine::CommandType;
3
4#[derive(Clone)]
5pub struct PluginUse;
6
7impl Command for PluginUse {
8 fn name(&self) -> &str {
9 "plugin use"
10 }
11
12 fn description(&self) -> &str {
13 "Load a plugin from the plugin registry file into scope."
14 }
15
16 fn signature(&self) -> nu_protocol::Signature {
17 Signature::build(self.name())
18 .input_output_types(vec![(Type::Nothing, Type::Nothing)])
19 .named(
20 "plugin-config",
21 SyntaxShape::Filepath,
22 "Use a plugin registry file other than the one set in `$nu.plugin-path`",
23 None,
24 )
25 .required(
26 "name",
27 SyntaxShape::String,
28 "The name, or filename, of the plugin to load.",
29 )
30 .category(Category::Plugin)
31 }
32
33 fn extra_description(&self) -> &str {
34 r#"
35This command is a parser keyword. For details, check:
36 https://www.nushell.sh/book/thinking_in_nu.html
37
38The plugin definition must be available in the plugin registry file at parse
39time. Run `plugin add` first in the REPL to do this, or from a script consider
40preparing a plugin registry file and passing `--plugin-config`, or using the
41`--plugin` option to `nu` instead.
42
43If the plugin was already loaded, this will reload the latest definition from
44the registry file into scope.
45
46Note that even if the plugin filename is specified, it will only be loaded if
47it was already previously registered with `plugin add`.
48"#
49 .trim()
50 }
51
52 fn search_terms(&self) -> Vec<&str> {
53 vec!["add", "register", "scope"]
54 }
55
56 fn command_type(&self) -> CommandType {
57 CommandType::Keyword
58 }
59
60 fn run(
61 &self,
62 _engine_state: &EngineState,
63 _stack: &mut Stack,
64 _call: &Call,
65 _input: PipelineData,
66 ) -> Result<PipelineData, ShellError> {
67 Ok(PipelineData::empty())
68 }
69
70 fn examples(&self) -> Vec<Example<'_>> {
71 vec![
72 Example {
73 description: "Load the commands for the `query` plugin from $nu.plugin-path",
74 example: r#"plugin use query"#,
75 result: None,
76 },
77 Example {
78 description: "Load the commands for the plugin with the filename `~/.cargo/bin/nu_plugin_query` from $nu.plugin-path",
79 example: r#"plugin use ~/.cargo/bin/nu_plugin_query"#,
80 result: None,
81 },
82 Example {
83 description: "Load the commands for the `query` plugin from a custom plugin registry file",
84 example: r#"plugin use --plugin-config local-plugins.msgpackz query"#,
85 result: None,
86 },
87 ]
88 }
89}