Exclude internal commands from 'help command' (#2573)

This commit is contained in:
Chris Gillespie 2020-09-18 16:48:30 -07:00 committed by GitHub
parent dd27aaef1b
commit 4c10351579
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 5 deletions

View File

@ -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<Example> {
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
}

View File

@ -64,17 +64,27 @@ async fn help(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStr
sorted_names.sort();
Ok(
futures::stream::iter(sorted_names.into_iter().filter_map(move |cmd| {
futures::stream::iter(sorted_names.into_iter().filter_map(move |cmd_name| {
// If it's a subcommand, don't list it during the commands list
if cmd.contains(' ') {
if cmd_name.contains(' ') {
return None;
}
// Internal only commands shouldn't be displayed
let command = match registry.get_command(&cmd_name) {
Some(c) => 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<OutputStr
name.clone(),
);
short_desc.insert_untagged("name", cmd);
short_desc.insert_untagged("name", cmd_name);
short_desc.insert_untagged(
"description",
match match get_data_by_key(&value, "usage".spanned_unknown()).ok_or_else(

View File

@ -59,6 +59,10 @@ impl WholeStreamCommand for RunExternalCommand {
}]
}
fn is_internal(&self) -> bool {
true
}
async fn run(
&self,
args: CommandArgs,