Short-hand flags (#1378)

* typo fixes

* Change signature to take in short-hand flags

* update help information

* Parse short-hand flags as their long counterparts

* lints

* Modified a couple tests to use shorthand flags
This commit is contained in:
Corvus Corax
2020-02-11 20:24:31 -06:00
committed by GitHub
parent 2ab8d035e6
commit c0be02a434
46 changed files with 344 additions and 110 deletions

View File

@ -361,9 +361,20 @@ impl SpannedToken {
}
}
pub(crate) fn as_flag(&self, value: &str, source: &Text) -> Option<Flag> {
pub(crate) fn as_flag(&self, value: &str, short: Option<char>, source: &Text) -> Option<Flag> {
match self.unspanned() {
Token::Flag(flag @ Flag { .. }) if value == flag.name().slice(source) => Some(*flag),
Token::Flag(flag @ Flag { .. }) => {
let name = flag.name().slice(source);
let is_long = flag.kind == FlagKind::Longhand && value == name;
let is_short = flag.kind == FlagKind::Shorthand
&& short.is_some()
&& short == name.chars().nth(0);
if is_long || is_short {
Some(*flag)
} else {
None
}
}
_ => None,
}
}