forked from extern/nushell
Differentiate internal signature from external signature w.r.t. help (#5667)
* Differentiate internal signature from external signature w.r.t. help * Add in the --help flag to default externs in default config * Remove unusued build_extern Co-authored-by: mjclements <clements.michael.james@gmail.com>
This commit is contained in:
@ -54,7 +54,6 @@ pub fn parse_def_predecl(
|
||||
let (sig, ..) = parse_signature(working_set, spans[2], expand_aliases_denylist);
|
||||
let signature = sig.as_signature();
|
||||
working_set.exit_scope();
|
||||
|
||||
if let (Some(name), Some(mut signature)) = (name, signature) {
|
||||
signature.name = name;
|
||||
let decl = signature.predeclare();
|
||||
@ -360,6 +359,7 @@ pub fn parse_def(
|
||||
let declaration = working_set.get_decl_mut(decl_id);
|
||||
|
||||
signature.name = name.clone();
|
||||
*signature = signature.add_help();
|
||||
signature.usage = usage;
|
||||
|
||||
*declaration = signature.clone().into_block_command(block_id);
|
||||
|
@ -124,6 +124,23 @@ impl Eq for Signature {}
|
||||
|
||||
impl Signature {
|
||||
pub fn new(name: impl Into<String>) -> Signature {
|
||||
Signature {
|
||||
name: name.into(),
|
||||
usage: String::new(),
|
||||
extra_usage: String::new(),
|
||||
search_terms: vec![],
|
||||
required_positional: vec![],
|
||||
optional_positional: vec![],
|
||||
rest_positional: None,
|
||||
named: vec![],
|
||||
is_filter: false,
|
||||
creates_scope: false,
|
||||
category: Category::Default,
|
||||
}
|
||||
}
|
||||
|
||||
// Add a default help option to a signature
|
||||
pub fn add_help(mut self) -> Signature {
|
||||
// default help flag
|
||||
let flag = Flag {
|
||||
long: "help".into(),
|
||||
@ -134,24 +151,13 @@ impl Signature {
|
||||
var_id: None,
|
||||
default_value: None,
|
||||
};
|
||||
|
||||
Signature {
|
||||
name: name.into(),
|
||||
usage: String::new(),
|
||||
extra_usage: String::new(),
|
||||
search_terms: vec![],
|
||||
required_positional: vec![],
|
||||
optional_positional: vec![],
|
||||
rest_positional: None,
|
||||
named: vec![flag],
|
||||
is_filter: false,
|
||||
creates_scope: false,
|
||||
category: Category::Default,
|
||||
}
|
||||
self.named.push(flag);
|
||||
self
|
||||
}
|
||||
|
||||
// Build an internal signature with default help option
|
||||
pub fn build(name: impl Into<String>) -> Signature {
|
||||
Signature::new(name.into())
|
||||
Signature::new(name.into()).add_help()
|
||||
}
|
||||
|
||||
/// Add a description to the signature
|
||||
|
@ -31,13 +31,10 @@ fn test_signature_chained() {
|
||||
|
||||
assert_eq!(signature.required_positional.len(), 1);
|
||||
assert_eq!(signature.optional_positional.len(), 1);
|
||||
assert_eq!(signature.named.len(), 4); // The 3 above + help
|
||||
assert_eq!(signature.named.len(), 3);
|
||||
assert!(signature.rest_positional.is_some());
|
||||
assert_eq!(signature.get_shorts(), vec!['h', 'r', 'n']);
|
||||
assert_eq!(
|
||||
signature.get_names(),
|
||||
vec!["help", "req-named", "named", "switch"]
|
||||
);
|
||||
assert_eq!(signature.get_shorts(), vec!['r', 'n']);
|
||||
assert_eq!(signature.get_names(), vec!["req-named", "named", "switch"]);
|
||||
assert_eq!(signature.num_positionals(), 2);
|
||||
|
||||
assert_eq!(
|
||||
|
Reference in New Issue
Block a user