allow -h flags for export subcommands (#6189)

* allow `-h` flags for `export` subcommands

* remove unnecessary check

* add tests

* fmt
This commit is contained in:
pwygab 2022-08-02 23:26:16 +08:00 committed by GitHub
parent 56069af42d
commit 233afebdf0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 3 deletions

View file

@ -0,0 +1,15 @@
use nu_test_support::{nu, pipeline};
#[test]
fn export_subcommands_help() {
let actual = nu!(
cwd: ".", pipeline(
r#"
export def -h
"#
));
assert!(actual
.out
.contains("Define a custom command and export it from a module"));
}

View file

@ -17,6 +17,7 @@ mod empty;
mod enter; mod enter;
mod error_make; mod error_make;
mod every; mod every;
mod export_def;
mod find; mod find;
mod first; mod first;
mod flatten; mod flatten;

View file

@ -4794,11 +4794,30 @@ pub fn parse_builtin_commands(
b"overlay" => parse_overlay(working_set, &lite_command.parts, expand_aliases_denylist), b"overlay" => parse_overlay(working_set, &lite_command.parts, expand_aliases_denylist),
b"source" => parse_source(working_set, &lite_command.parts, expand_aliases_denylist), b"source" => parse_source(working_set, &lite_command.parts, expand_aliases_denylist),
b"export" => { b"export" => {
if let Some(decl_id) = working_set.find_decl(b"export", &Type::Any) { let full_decl = if lite_command.parts.len() > 1 {
let sub = working_set.get_span_contents(lite_command.parts[1]);
match sub {
b"alias" | b"def" | b"def-env" | b"env" | b"extern" | b"use" => {
[b"export ", sub].concat()
}
_ => b"export".to_vec(),
}
} else {
b"export".to_vec()
};
if let Some(decl_id) = working_set.find_decl(&full_decl, &Type::Any) {
let parsed_call = parse_internal_call( let parsed_call = parse_internal_call(
working_set, working_set,
lite_command.parts[0], if full_decl == b"export" {
&lite_command.parts[1..], lite_command.parts[0]
} else {
span(&lite_command.parts[0..2])
},
if full_decl == b"export" {
&lite_command.parts[1..]
} else {
&lite_command.parts[2..]
},
decl_id, decl_id,
expand_aliases_denylist, expand_aliases_denylist,
); );