mirror of
https://github.com/nushell/nushell.git
synced 2025-08-17 23:39:48 +02:00
Add the default help flag
This commit is contained in:
@@ -54,6 +54,16 @@ impl Eq for Signature {}
|
||||
|
||||
impl Signature {
|
||||
pub fn new(name: impl Into<String>) -> Signature {
|
||||
// default help flag
|
||||
let flag = Flag {
|
||||
long: "help".into(),
|
||||
short: Some('h'),
|
||||
arg: None,
|
||||
desc: "Display this help message".into(),
|
||||
required: false,
|
||||
var_id: None,
|
||||
};
|
||||
|
||||
Signature {
|
||||
name: name.into(),
|
||||
usage: String::new(),
|
||||
@@ -61,7 +71,7 @@ impl Signature {
|
||||
required_positional: vec![],
|
||||
optional_positional: vec![],
|
||||
rest_positional: None,
|
||||
named: vec![],
|
||||
named: vec![flag],
|
||||
is_filter: false,
|
||||
creates_scope: false,
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ where
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
pub struct Span {
|
||||
pub start: usize,
|
||||
pub end: usize,
|
||||
@@ -37,6 +37,10 @@ impl Span {
|
||||
end: self.end - offset,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn contains(&self, pos: usize) -> bool {
|
||||
pos >= self.start && pos < self.end
|
||||
}
|
||||
}
|
||||
|
||||
pub fn span(spans: &[Span]) -> Span {
|
||||
|
@@ -31,10 +31,13 @@ fn test_signature_chained() {
|
||||
|
||||
assert_eq!(signature.required_positional.len(), 1);
|
||||
assert_eq!(signature.optional_positional.len(), 1);
|
||||
assert_eq!(signature.named.len(), 3);
|
||||
assert_eq!(signature.named.len(), 4); // The 3 above + help
|
||||
assert!(signature.rest_positional.is_some());
|
||||
assert_eq!(signature.get_shorts(), vec!['r', 'n']);
|
||||
assert_eq!(signature.get_names(), vec!["req_named", "named", "switch"]);
|
||||
assert_eq!(signature.get_shorts(), vec!['h', 'r', 'n']);
|
||||
assert_eq!(
|
||||
signature.get_names(),
|
||||
vec!["help", "req_named", "named", "switch"]
|
||||
);
|
||||
assert_eq!(signature.num_positionals(), 2);
|
||||
|
||||
assert_eq!(
|
||||
|
Reference in New Issue
Block a user