Use CommandType in more places (#12832)

# Description
Kind of a vague title, but this PR does two main things:
1. Rather than overriding functions like `Command::is_parser_keyword`,
this PR instead changes commands to override `Command::command_type`.
The `CommandType` returned by `Command::command_type` is then used to
automatically determine whether `Command::is_parser_keyword` and the
other `is_{type}` functions should return true. These changes allow us
to remove the `CommandType::Other` case and should also guarantee than
only one of the `is_{type}` functions on `Command` will return true.
2. Uses the new, reworked `Command::command_type` function in the `scope
commands` and `which` commands.


# User-Facing Changes
- Breaking change for `scope commands`: multiple columns (`is_builtin`,
`is_keyword`, `is_plugin`, etc.) have been merged into the `type`
column.
- Breaking change: the `which` command can now report `plugin` or
`keyword` instead of `built-in` in the `type` column. It may also now
report `external` instead of `custom` in the `type` column for known
`extern`s.
This commit is contained in:
Ian Manske
2024-05-18 23:37:31 +00:00
committed by GitHub
parent 580c60bb82
commit cc9f41e553
68 changed files with 224 additions and 217 deletions

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct Alias;
@ -29,8 +30,8 @@ impl Command for Alias {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn search_terms(&self) -> Vec<&str> {

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct Const;
@ -30,8 +31,8 @@ impl Command for Const {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn search_terms(&self) -> Vec<&str> {

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct Def;
@ -28,8 +29,8 @@ impl Command for Def {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(

View File

@ -1,4 +1,5 @@
use nu_engine::{command_prelude::*, get_full_help};
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct ExportCommand;
@ -23,8 +24,8 @@ impl Command for ExportCommand {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(
@ -40,7 +41,7 @@ impl Command for ExportCommand {
&ExportCommand.examples(),
engine_state,
stack,
self.is_parser_keyword(),
self.is_keyword(),
),
call.head,
)

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct ExportAlias;
@ -29,8 +30,8 @@ impl Command for ExportAlias {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn search_terms(&self) -> Vec<&str> {

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct ExportConst;
@ -30,8 +31,8 @@ impl Command for ExportConst {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct ExportDef;
@ -28,8 +29,8 @@ impl Command for ExportDef {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct ExportExtern;
@ -25,8 +26,8 @@ impl Command for ExportExtern {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct ExportModule;
@ -30,8 +31,8 @@ impl Command for ExportModule {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct ExportUse;
@ -29,8 +30,8 @@ impl Command for ExportUse {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct Extern;
@ -25,8 +26,8 @@ impl Command for Extern {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(

View File

@ -1,4 +1,5 @@
use nu_engine::{command_prelude::*, get_eval_block, get_eval_expression};
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct For;
@ -41,8 +42,8 @@ impl Command for For {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct Hide;
@ -31,8 +32,8 @@ This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(

View File

@ -1,4 +1,5 @@
use nu_engine::{command_prelude::*, get_eval_block};
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct Let;
@ -30,8 +31,8 @@ impl Command for Let {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn search_terms(&self) -> Vec<&str> {

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct Module;
@ -30,8 +31,8 @@ impl Command for Module {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(

View File

@ -1,4 +1,5 @@
use nu_engine::{command_prelude::*, get_eval_block};
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct Mut;
@ -30,8 +31,8 @@ impl Command for Mut {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn search_terms(&self) -> Vec<&str> {

View File

@ -1,4 +1,5 @@
use nu_engine::{command_prelude::*, get_full_help};
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct Overlay;
@ -25,8 +26,8 @@ impl Command for Overlay {
You must use one of the following subcommands. Using this command as-is will only produce this help message."#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(
@ -42,7 +43,7 @@ impl Command for Overlay {
&[],
engine_state,
stack,
self.is_parser_keyword(),
self.is_keyword(),
),
call.head,
)

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct OverlayHide;
@ -35,8 +36,8 @@ impl Command for OverlayHide {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct OverlayNew;
@ -33,8 +34,8 @@ This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(

View File

@ -2,7 +2,7 @@ use nu_engine::{
command_prelude::*, find_in_dirs_env, get_dirs_var_from_call, get_eval_block, redirect_env,
};
use nu_parser::trim_quotes_str;
use nu_protocol::ast::Expr;
use nu_protocol::{ast::Expr, engine::CommandType};
use std::path::Path;
@ -50,8 +50,8 @@ impl Command for OverlayUse {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct Return;
@ -28,8 +29,8 @@ impl Command for Return {
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(

View File

@ -1,4 +1,5 @@
use nu_engine::{command_prelude::*, get_full_help};
use nu_protocol::engine::CommandType;
#[derive(Clone)]
pub struct Scope;
@ -19,8 +20,8 @@ impl Command for Scope {
"Commands for getting info about what is in scope."
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(
@ -36,7 +37,7 @@ impl Command for Scope {
&[],
engine_state,
stack,
self.is_parser_keyword(),
self.is_keyword(),
),
call.head,
)

View File

@ -1,7 +1,10 @@
use nu_engine::{
command_prelude::*, find_in_dirs_env, get_dirs_var_from_call, get_eval_block, redirect_env,
};
use nu_protocol::ast::{Expr, Expression};
use nu_protocol::{
ast::{Expr, Expression},
engine::CommandType,
};
#[derive(Clone)]
pub struct Use;
@ -40,8 +43,8 @@ This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn is_parser_keyword(&self) -> bool {
true
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run(