mirror of
https://github.com/nushell/nushell.git
synced 2024-12-01 21:03:58 +01:00
feat: Add default docs for aliases, generated from the command they point to (#10825)
This commit is contained in:
parent
c9aa6ba0f3
commit
fc06afd051
@ -155,3 +155,11 @@ fn alias_ordering() {
|
|||||||
let actual = nu!(r#"alias bar = echo; def echo [] { 'dummy echo' }; bar 'foo'"#);
|
let actual = nu!(r#"alias bar = echo; def echo [] { 'dummy echo' }; bar 'foo'"#);
|
||||||
assert_eq!(actual.out, "foo");
|
assert_eq!(actual.out, "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn alias_default_help() {
|
||||||
|
let actual = nu!("alias teapot = echo 'I am a beautiful teapot'; help teapot");
|
||||||
|
// There must be at least one line of help
|
||||||
|
let first_help_line = actual.out.lines().next().unwrap();
|
||||||
|
assert!(first_help_line.starts_with("Alias for `echo 'I am a beautiful teapot'`"));
|
||||||
|
}
|
||||||
|
@ -856,7 +856,6 @@ pub fn parse_alias(
|
|||||||
|
|
||||||
if let Some(decl_id) = working_set.find_decl(b"alias") {
|
if let Some(decl_id) = working_set.find_decl(b"alias") {
|
||||||
let (command_spans, rest_spans) = spans.split_at(split_id);
|
let (command_spans, rest_spans) = spans.split_at(split_id);
|
||||||
let (usage, extra_usage) = working_set.build_usage(&lite_command.comments);
|
|
||||||
|
|
||||||
let original_starting_error_count = working_set.parse_errors.len();
|
let original_starting_error_count = working_set.parse_errors.len();
|
||||||
|
|
||||||
@ -865,6 +864,7 @@ pub fn parse_alias(
|
|||||||
output,
|
output,
|
||||||
..
|
..
|
||||||
} = parse_internal_call(working_set, span(command_spans), rest_spans, decl_id);
|
} = parse_internal_call(working_set, span(command_spans), rest_spans, decl_id);
|
||||||
|
|
||||||
working_set
|
working_set
|
||||||
.parse_errors
|
.parse_errors
|
||||||
.truncate(original_starting_error_count);
|
.truncate(original_starting_error_count);
|
||||||
@ -1010,6 +1010,27 @@ pub fn parse_alias(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Tries to build a useful usage string
|
||||||
|
let (usage, extra_usage) = match lite_command.comments.is_empty() {
|
||||||
|
// First from comments, if any are present
|
||||||
|
false => working_set.build_usage(&lite_command.comments),
|
||||||
|
// Then from the command itself
|
||||||
|
true => match alias_call.arguments.get(1) {
|
||||||
|
Some(Argument::Positional(Expression {
|
||||||
|
expr: Expr::Keyword(.., expr),
|
||||||
|
..
|
||||||
|
})) => {
|
||||||
|
let aliased = working_set.get_span_contents(expr.span);
|
||||||
|
(
|
||||||
|
format!("Alias for `{}`", String::from_utf8_lossy(aliased)),
|
||||||
|
String::new(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
// Then with a default.
|
||||||
|
_ => ("User declared alias".into(), String::new()),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
let decl = Alias {
|
let decl = Alias {
|
||||||
name: alias_name,
|
name: alias_name,
|
||||||
command,
|
command,
|
||||||
|
Loading…
Reference in New Issue
Block a user