Make commands keywords

This commit is contained in:
Ian Manske 2024-06-23 19:22:43 -07:00
parent 9b7f899410
commit 3393f84be2
11 changed files with 99 additions and 9 deletions

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*; use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)] #[derive(Clone)]
pub struct Break; pub struct Break;
@ -18,6 +19,15 @@ impl Command for Break {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -1,4 +1,5 @@
use nu_engine::command_prelude::*; use nu_engine::command_prelude::*;
use nu_protocol::engine::CommandType;
#[derive(Clone)] #[derive(Clone)]
pub struct Continue; pub struct Continue;
@ -18,6 +19,14 @@ impl Command for Continue {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -1,5 +1,5 @@
use nu_engine::command_prelude::*; use nu_engine::command_prelude::*;
use nu_protocol::did_you_mean; use nu_protocol::{did_you_mean, engine::CommandType};
#[derive(Clone)] #[derive(Clone)]
pub struct HideEnv; pub struct HideEnv;
@ -29,6 +29,15 @@ impl Command for HideEnv {
"Hide environment variables in the current scope." "Hide environment variables in the current scope."
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -2,7 +2,7 @@ use nu_engine::{
command_prelude::*, get_eval_block, get_eval_expression, get_eval_expression_with_input, command_prelude::*, get_eval_block, get_eval_expression, get_eval_expression_with_input,
}; };
use nu_protocol::{ use nu_protocol::{
engine::StateWorkingSet, engine::{CommandType, StateWorkingSet},
eval_const::{eval_const_subexpression, eval_constant, eval_constant_with_input}, eval_const::{eval_const_subexpression, eval_constant, eval_constant_with_input},
}; };
@ -41,6 +41,15 @@ impl Command for If {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn is_const(&self) -> bool { fn is_const(&self) -> bool {
true true
} }

View File

@ -1,4 +1,5 @@
use nu_engine::{command_prelude::*, get_eval_block}; use nu_engine::{command_prelude::*, get_eval_block};
use nu_protocol::engine::CommandType;
#[derive(Clone)] #[derive(Clone)]
pub struct Loop; pub struct Loop;
@ -20,6 +21,15 @@ impl Command for Loop {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1,7 +1,7 @@
use nu_engine::{ use nu_engine::{
command_prelude::*, get_eval_block, get_eval_expression, get_eval_expression_with_input, command_prelude::*, get_eval_block, get_eval_expression, get_eval_expression_with_input,
}; };
use nu_protocol::engine::Matcher; use nu_protocol::engine::{CommandType, Matcher};
#[derive(Clone)] #[derive(Clone)]
pub struct Match; pub struct Match;
@ -27,6 +27,15 @@ impl Command for Match {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1,5 +1,4 @@
use nu_engine::{command_prelude::*, get_full_help}; use nu_engine::{command_prelude::*, get_full_help};
use nu_protocol::engine::CommandType;
#[derive(Clone)] #[derive(Clone)]
pub struct Scope; pub struct Scope;
@ -20,10 +19,6 @@ impl Command for Scope {
"Commands for getting info about what is in scope." "Commands for getting info about what is in scope."
} }
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1,5 +1,5 @@
use nu_engine::{command_prelude::*, get_eval_block, EvalBlockFn}; use nu_engine::{command_prelude::*, get_eval_block, EvalBlockFn};
use nu_protocol::engine::Closure; use nu_protocol::engine::{Closure, CommandType};
#[derive(Clone)] #[derive(Clone)]
pub struct Try; pub struct Try;
@ -31,6 +31,15 @@ impl Command for Try {
.category(Category::Core) .category(Category::Core)
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1,4 +1,5 @@
use nu_engine::{command_prelude::*, get_eval_block, get_eval_expression}; use nu_engine::{command_prelude::*, get_eval_block, get_eval_expression};
use nu_protocol::engine::CommandType;
#[derive(Clone)] #[derive(Clone)]
pub struct While; pub struct While;
@ -29,6 +30,15 @@ impl Command for While {
vec!["loop"] vec!["loop"]
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1,4 +1,5 @@
use nu_engine::{command_prelude::*, get_eval_block, redirect_env}; use nu_engine::{command_prelude::*, get_eval_block, redirect_env};
use nu_protocol::engine::CommandType;
#[derive(Clone)] #[derive(Clone)]
pub struct ExportEnv; pub struct ExportEnv;
@ -23,6 +24,15 @@ impl Command for ExportEnv {
"Run a block and preserve its environment in a current scope." "Run a block and preserve its environment in a current scope."
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -2,6 +2,7 @@ use nu_engine::{
command_prelude::*, find_in_dirs_env, get_dirs_var_from_call, get_eval_block_with_early_return, command_prelude::*, find_in_dirs_env, get_dirs_var_from_call, get_eval_block_with_early_return,
redirect_env, redirect_env,
}; };
use nu_protocol::engine::CommandType;
use std::path::PathBuf; use std::path::PathBuf;
/// Source a file for environment variables. /// Source a file for environment variables.
@ -28,6 +29,15 @@ impl Command for SourceEnv {
"Source the environment from a source file into the current environment." "Source the environment from a source file into the current environment."
} }
fn extra_usage(&self) -> &str {
r#"This command is a parser keyword. For details, check:
https://www.nushell.sh/book/thinking_in_nu.html"#
}
fn command_type(&self) -> CommandType {
CommandType::Keyword
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,