mirror of
https://github.com/nushell/nushell
synced 2024-12-27 13:33:16 +00:00
allow -h
flags for export
subcommands (#6189)
* allow `-h` flags for `export` subcommands * remove unnecessary check * add tests * fmt
This commit is contained in:
parent
56069af42d
commit
233afebdf0
3 changed files with 38 additions and 3 deletions
15
crates/nu-command/tests/commands/export_def.rs
Normal file
15
crates/nu-command/tests/commands/export_def.rs
Normal 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"));
|
||||
}
|
|
@ -17,6 +17,7 @@ mod empty;
|
|||
mod enter;
|
||||
mod error_make;
|
||||
mod every;
|
||||
mod export_def;
|
||||
mod find;
|
||||
mod first;
|
||||
mod flatten;
|
||||
|
|
|
@ -4794,11 +4794,30 @@ pub fn parse_builtin_commands(
|
|||
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"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(
|
||||
working_set,
|
||||
lite_command.parts[0],
|
||||
&lite_command.parts[1..],
|
||||
if full_decl == b"export" {
|
||||
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,
|
||||
expand_aliases_denylist,
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue