Collapse some help commands columns into a single column (#7052)

This commit is contained in:
Dan Davison 2022-11-09 20:44:32 -05:00 committed by GitHub
parent 24d72ca43c
commit fe14e52e77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 30 deletions

View File

@ -136,21 +136,9 @@ fn help(
span: head,
});
cols.push("is_plugin".into());
vals.push(Value::Bool {
val: decl.is_plugin().is_some(),
span: head,
});
cols.push("is_custom".into());
vals.push(Value::Bool {
val: decl.is_custom_command(),
span: head,
});
cols.push("is_keyword".into());
vals.push(Value::Bool {
val: decl.is_parser_keyword(),
cols.push("command_type".into());
vals.push(Value::String {
val: format!("{:?}", decl.command_type()).to_lowercase(),
span: head,
});
@ -247,21 +235,9 @@ fn help(
span: head,
});
cols.push("is_plugin".into());
vals.push(Value::Bool {
val: decl.is_plugin().is_some(),
span: head,
});
cols.push("is_custom".into());
vals.push(Value::Bool {
val: decl.is_custom_command(),
span: head,
});
cols.push("is_keyword".into());
vals.push(Value::Bool {
val: decl.is_parser_keyword(),
cols.push("command_type".into());
vals.push(Value::String {
val: format!("{:?}", decl.command_type()).to_lowercase(),
span: head,
});

View File

@ -4,6 +4,15 @@ use crate::{ast::Call, BlockId, Example, PipelineData, ShellError, Signature};
use super::{EngineState, Stack};
#[derive(Debug)]
pub enum CommandType {
Builtin,
Custom,
Keyword,
Plugin,
Other,
}
pub trait Command: Send + Sync + CommandClone {
fn name(&self) -> &str;
@ -71,6 +80,21 @@ pub trait Command: Send + Sync + CommandClone {
fn search_terms(&self) -> Vec<&str> {
vec![]
}
fn command_type(&self) -> CommandType {
match (
self.is_builtin(),
self.is_custom_command(),
self.is_parser_keyword(),
self.is_plugin().is_some(),
) {
(true, false, false, false) => CommandType::Builtin,
(false, true, false, false) => CommandType::Custom,
(_, false, true, false) => CommandType::Keyword,
(false, false, false, true) => CommandType::Plugin,
_ => CommandType::Other,
}
}
}
pub trait CommandClone {