Remove parser keywords label from commands that do not need it (#8780)

This commit is contained in:
Jakub Žádník 2023-04-07 01:12:21 +03:00 committed by GitHub
parent c12b4b4af7
commit e54b867e8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 21 additions and 64 deletions

View File

@ -20,15 +20,6 @@ impl Command for Break {
.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 is_parser_keyword(&self) -> bool {
true
}
fn run(
&self,
_engine_state: &EngineState,

View File

@ -20,15 +20,6 @@ impl Command for Continue {
.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 is_parser_keyword(&self) -> bool {
true
}
fn run(
&self,
_engine_state: &EngineState,

View File

@ -40,15 +40,6 @@ impl Command for If {
.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 is_parser_keyword(&self) -> bool {
true
}
fn run(
&self,
engine_state: &EngineState,

View File

@ -25,15 +25,6 @@ impl Command for Loop {
.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 is_parser_keyword(&self) -> bool {
true
}
fn run(
&self,
engine_state: &EngineState,

View File

@ -29,15 +29,6 @@ impl Command for Match {
.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 is_parser_keyword(&self) -> bool {
true
}
fn run(
&self,
engine_state: &EngineState,

View File

@ -36,15 +36,6 @@ impl Command for Try {
.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 is_parser_keyword(&self) -> bool {
true
}
fn run(
&self,
engine_state: &EngineState,

View File

@ -30,15 +30,6 @@ impl Command for While {
.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 is_parser_keyword(&self) -> bool {
true
}
fn run(
&self,
engine_state: &EngineState,

View File

@ -126,6 +126,18 @@ fn alias_invalid_expression() {
assert!(actual.err.contains("cant_alias_expression"));
}
#[test]
fn alias_if() {
let actual = nu!(r#" alias spam = if true { 'spam' } else { 'eggs' }; spam "#);
assert_eq!(actual.out, "spam");
}
#[test]
fn alias_match() {
let actual = nu!(r#" alias spam = match 3 { 1..10 => 'yes!' }; spam "#);
assert_eq!(actual.out, "yes!");
}
// Issue https://github.com/nushell/nushell/issues/8103
#[test]
fn alias_multiword_name() {

View File

@ -798,8 +798,16 @@ pub fn parse_alias(
let _equals = working_set.get_span_contents(spans[split_id + 1]);
let replacement_spans = &spans[(split_id + 2)..];
let first_bytes = working_set.get_span_contents(replacement_spans[0]);
if is_math_expression_like(working_set, replacement_spans[0], expand_aliases_denylist) {
if first_bytes != b"if"
&& first_bytes != b"match"
&& is_math_expression_like(
working_set,
replacement_spans[0],
expand_aliases_denylist,
)
{
// TODO: Maybe we need to implement a Display trait for Expression?
let (expr, _) = parse_expression(
working_set,