From bb0d08a72143181d6a552e02ee9db51cc6559a6a Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Wed, 9 Nov 2022 22:09:33 -0500 Subject: [PATCH] Fix command_type classification (#7074) - Custom commands are true for builtin and custom - Add classification as external command - Specify wildcard in keyword: keyword is true for builtin and keyword --- crates/nu-command/src/core_commands/let_.rs | 7 +++++++ crates/nu-command/src/filters/sort.rs | 8 ++++++++ crates/nu-protocol/src/engine/command.rs | 11 +++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/crates/nu-command/src/core_commands/let_.rs b/crates/nu-command/src/core_commands/let_.rs index 23dcb70117..aa2be155db 100644 --- a/crates/nu-command/src/core_commands/let_.rs +++ b/crates/nu-command/src/core_commands/let_.rs @@ -99,6 +99,8 @@ impl Command for Let { #[cfg(test)] mod test { + use nu_protocol::engine::CommandType; + use super::*; #[test] @@ -107,4 +109,9 @@ mod test { test_examples(Let {}) } + + #[test] + fn test_command_type() { + assert!(matches!(Let.command_type(), CommandType::Keyword)); + } } diff --git a/crates/nu-command/src/filters/sort.rs b/crates/nu-command/src/filters/sort.rs index a7a982df12..67f5d0ebcd 100644 --- a/crates/nu-command/src/filters/sort.rs +++ b/crates/nu-command/src/filters/sort.rs @@ -292,6 +292,9 @@ pub fn process( #[cfg(test)] mod test { + + use nu_protocol::engine::CommandType; + use super::*; #[test] @@ -300,4 +303,9 @@ mod test { test_examples(Sort {}) } + + #[test] + fn test_command_type() { + assert!(matches!(Sort.command_type(), CommandType::Builtin)); + } } diff --git a/crates/nu-protocol/src/engine/command.rs b/crates/nu-protocol/src/engine/command.rs index 3b782448e3..9a54992230 100644 --- a/crates/nu-protocol/src/engine/command.rs +++ b/crates/nu-protocol/src/engine/command.rs @@ -9,6 +9,7 @@ pub enum CommandType { Builtin, Custom, Keyword, + External, Plugin, Other, } @@ -86,12 +87,14 @@ pub trait Command: Send + Sync + CommandClone { self.is_builtin(), self.is_custom_command(), self.is_parser_keyword(), + self.is_known_external(), 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, + (true, false, false, false, false) => CommandType::Builtin, + (true, true, false, false, false) => CommandType::Custom, + (true, false, true, false, false) => CommandType::Keyword, + (false, true, false, true, false) => CommandType::External, + (false, false, false, false, true) => CommandType::Plugin, _ => CommandType::Other, } }