Add support for custom subcommands (#2814)

* Add support for custom subcommands

* clippy
This commit is contained in:
Jonathan Turner 2020-12-23 20:43:56 +13:00 committed by GitHub
parent 1e67ae8e94
commit f22938fc4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -2130,7 +2130,7 @@ fn parse_definition(call: &LiteCommand, scope: &dyn ParserScope) -> Option<Parse
return Some(ParseError::mismatch("definition", call.parts[0].clone()));
}
let name = call.parts[1].item.clone();
let name = trim_quotes(&call.parts[1].item);
let (signature, err) = parse_signature(&name, &call.parts[2], scope);
if err.is_some() {
return err;
@ -2151,11 +2151,10 @@ fn parse_definition(call: &LiteCommand, scope: &dyn ParserScope) -> Option<Parse
return err;
};
let name = &call.parts[1].item;
let (mut block, err) = classify_block(&lite_block, scope);
block.params = signature;
block.params.name = name.clone();
block.params.name = name;
scope.add_definition(block);
@ -2181,7 +2180,7 @@ fn parse_definition_prototype(call: &LiteCommand, scope: &dyn ParserScope) -> Op
return Some(ParseError::mismatch("definition", call.parts[0].clone()));
}
let name = call.parts[1].item.clone();
let name = trim_quotes(&call.parts[1].item);
let (signature, error) = parse_signature(&name, &call.parts[2], scope);
if err.is_none() {
err = error;

View File

@ -368,6 +368,18 @@ fn run_custom_command_with_flag_missing() {
assert_eq!(actual.out, "empty");
}
#[test]
fn run_custom_subcommand() {
let actual = nu!(
cwd: ".",
r#"
def "str double" [x] { echo $x $x | str collect }; str double bob
"#
);
assert_eq!(actual.out, "bobbob");
}
#[test]
fn set_variable() {
let actual = nu!(