From fe14e52e77b0d75f85fb8b7b292defcb8d4c6700 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Wed, 9 Nov 2022 20:44:32 -0500 Subject: [PATCH] Collapse some `help commands` columns into a single column (#7052) --- crates/nu-command/src/core_commands/help.rs | 36 ++++----------------- crates/nu-protocol/src/engine/command.rs | 24 ++++++++++++++ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/crates/nu-command/src/core_commands/help.rs b/crates/nu-command/src/core_commands/help.rs index c98dc44c1a..25ab9fda3c 100644 --- a/crates/nu-command/src/core_commands/help.rs +++ b/crates/nu-command/src/core_commands/help.rs @@ -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, }); diff --git a/crates/nu-protocol/src/engine/command.rs b/crates/nu-protocol/src/engine/command.rs index 0fa1e22799..3b782448e3 100644 --- a/crates/nu-protocol/src/engine/command.rs +++ b/crates/nu-protocol/src/engine/command.rs @@ -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 {