forked from extern/nushell
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:
@ -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,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user