diff --git a/crates/nu-command/src/core_commands/help.rs b/crates/nu-command/src/core_commands/help.rs index 0c18160787..eddb83bddd 100644 --- a/crates/nu-command/src/core_commands/help.rs +++ b/crates/nu-command/src/core_commands/help.rs @@ -142,7 +142,7 @@ fn help( cols.push("is_custom".into()); vals.push(Value::Bool { - val: decl.get_block_id().is_some(), + val: decl.is_custom_command(), span: head, }); @@ -243,7 +243,7 @@ fn help( cols.push("is_custom".into()); vals.push(Value::Bool { - val: decl.get_block_id().is_some(), + val: decl.is_custom_command(), span: head, }); diff --git a/crates/nu-command/src/system/which_.rs b/crates/nu-command/src/system/which_.rs index fe09f8bf5e..baddb0f8b9 100644 --- a/crates/nu-command/src/system/which_.rs +++ b/crates/nu-command/src/system/which_.rs @@ -95,7 +95,7 @@ fn get_entry_in_aliases(engine_state: &EngineState, name: &str, span: Span) -> O fn get_entry_in_commands(engine_state: &EngineState, name: &str, span: Span) -> Option { if let Some(decl_id) = engine_state.find_decl(name.as_bytes(), &[]) { - let (msg, is_builtin) = if engine_state.get_decl(decl_id).get_block_id().is_some() { + let (msg, is_builtin) = if engine_state.get_decl(decl_id).is_custom_command() { ("Nushell custom command", false) } else { ("Nushell built-in command", true) diff --git a/crates/nu-engine/src/eval.rs b/crates/nu-engine/src/eval.rs index 81971b44c4..51da07a1e0 100644 --- a/crates/nu-engine/src/eval.rs +++ b/crates/nu-engine/src/eval.rs @@ -1101,7 +1101,7 @@ pub fn create_scope( cols.push("is_builtin".to_string()); // we can only be a is_builtin or is_custom, not both vals.push(Value::Bool { - val: decl.get_block_id().is_none(), + val: !decl.is_custom_command(), span, }); @@ -1119,7 +1119,7 @@ pub fn create_scope( cols.push("is_custom".to_string()); vals.push(Value::Bool { - val: decl.get_block_id().is_some(), + val: decl.is_custom_command(), span, }); diff --git a/crates/nu-parser/src/known_external.rs b/crates/nu-parser/src/known_external.rs index 70ac93f82a..ea40daf4f5 100644 --- a/crates/nu-parser/src/known_external.rs +++ b/crates/nu-parser/src/known_external.rs @@ -30,6 +30,10 @@ impl Command for KnownExternal { true } + fn is_builtin(&self) -> bool { + false + } + fn run( &self, engine_state: &EngineState, diff --git a/crates/nu-protocol/src/engine/command.rs b/crates/nu-protocol/src/engine/command.rs index 56f4fad5f2..7d9d0242e6 100644 --- a/crates/nu-protocol/src/engine/command.rs +++ b/crates/nu-protocol/src/engine/command.rs @@ -37,6 +37,16 @@ pub trait Command: Send + Sync + CommandClone { false } + // This is an enhanced method to determine if a command is custom command or not + // since extern "foo" [] and def "foo" [] behaves differently + fn is_custom_command(&self) -> bool { + if self.get_block_id().is_some() { + true + } else { + self.is_known_external() + } + } + // Is a sub command fn is_sub(&self) -> bool { self.name().contains(' ')