From 4c10351579d61158cc83b5811199a5270e86cbcd Mon Sep 17 00:00:00 2001 From: Chris Gillespie <6572184+gillespiecd@users.noreply.github.com> Date: Fri, 18 Sep 2020 16:48:30 -0700 Subject: [PATCH] Exclude internal commands from 'help command' (#2573) --- crates/nu-cli/src/commands/command.rs | 9 +++++++++ crates/nu-cli/src/commands/help.rs | 20 +++++++++++++++----- crates/nu-cli/src/commands/run_external.rs | 4 ++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/crates/nu-cli/src/commands/command.rs b/crates/nu-cli/src/commands/command.rs index f90fd2b5e..18a44f3a4 100644 --- a/crates/nu-cli/src/commands/command.rs +++ b/crates/nu-cli/src/commands/command.rs @@ -303,6 +303,11 @@ pub trait WholeStreamCommand: Send + Sync { false } + // Commands that are not meant to be run by users + fn is_internal(&self) -> bool { + false + } + fn examples(&self) -> Vec { Vec::new() } @@ -367,6 +372,10 @@ impl Command { self.0.is_binary() } + pub fn is_internal(&self) -> bool { + self.0.is_internal() + } + pub fn stream_command(&self) -> &dyn WholeStreamCommand { &*self.0 } diff --git a/crates/nu-cli/src/commands/help.rs b/crates/nu-cli/src/commands/help.rs index dd9afe30e..50cc09758 100644 --- a/crates/nu-cli/src/commands/help.rs +++ b/crates/nu-cli/src/commands/help.rs @@ -64,17 +64,27 @@ async fn help(args: CommandArgs, registry: &CommandRegistry) -> Result c, + None => return None, + }; + if command.is_internal() { + return None; + }; + let mut short_desc = TaggedDictBuilder::new(name.clone()); let document_tag = rest[0].tag.clone(); let value = command_dict( - match registry.get_command(&cmd).ok_or_else(|| { + match registry.get_command(&cmd_name).ok_or_else(|| { ShellError::labeled_error( - format!("Could not load {}", cmd), + format!("Could not load {}", cmd_name), "could not load command", document_tag, ) @@ -85,7 +95,7 @@ async fn help(args: CommandArgs, registry: &CommandRegistry) -> Result bool { + true + } + async fn run( &self, args: CommandArgs,