Change how to identify custom comamnd (#6187)

Co-authored-by: Frank <v-frankz@microsoft.com>
This commit is contained in:
Kangaxx-0 2022-08-02 16:40:07 -07:00 committed by GitHub
parent ce6df93d05
commit ebf845f431
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 5 deletions

View file

@ -142,7 +142,7 @@ fn help(
cols.push("is_custom".into()); cols.push("is_custom".into());
vals.push(Value::Bool { vals.push(Value::Bool {
val: decl.get_block_id().is_some(), val: decl.is_custom_command(),
span: head, span: head,
}); });
@ -243,7 +243,7 @@ fn help(
cols.push("is_custom".into()); cols.push("is_custom".into());
vals.push(Value::Bool { vals.push(Value::Bool {
val: decl.get_block_id().is_some(), val: decl.is_custom_command(),
span: head, span: head,
}); });

View file

@ -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<Value> { fn get_entry_in_commands(engine_state: &EngineState, name: &str, span: Span) -> Option<Value> {
if let Some(decl_id) = engine_state.find_decl(name.as_bytes(), &[]) { 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) ("Nushell custom command", false)
} else { } else {
("Nushell built-in command", true) ("Nushell built-in command", true)

View file

@ -1101,7 +1101,7 @@ pub fn create_scope(
cols.push("is_builtin".to_string()); cols.push("is_builtin".to_string());
// we can only be a is_builtin or is_custom, not both // we can only be a is_builtin or is_custom, not both
vals.push(Value::Bool { vals.push(Value::Bool {
val: decl.get_block_id().is_none(), val: !decl.is_custom_command(),
span, span,
}); });
@ -1119,7 +1119,7 @@ pub fn create_scope(
cols.push("is_custom".to_string()); cols.push("is_custom".to_string());
vals.push(Value::Bool { vals.push(Value::Bool {
val: decl.get_block_id().is_some(), val: decl.is_custom_command(),
span, span,
}); });

View file

@ -30,6 +30,10 @@ impl Command for KnownExternal {
true true
} }
fn is_builtin(&self) -> bool {
false
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View file

@ -37,6 +37,16 @@ pub trait Command: Send + Sync + CommandClone {
false 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 // Is a sub command
fn is_sub(&self) -> bool { fn is_sub(&self) -> bool {
self.name().contains(' ') self.name().contains(' ')