Add the default help flag

This commit is contained in:
JT
2021-10-14 06:53:27 +13:00
parent ff6cc2cbdd
commit fdd2c35fd9
8 changed files with 89 additions and 41 deletions

View File

@ -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,
}

View File

@ -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 {