mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 19:45:29 +00:00
Merge pull request #15 from vrmiguel/oof-argparsing-shoft-arg-flags-fix
Fixing short flags not receiving values
This commit is contained in:
commit
94ecc63886
@ -126,7 +126,7 @@ pub fn filter_flags(
|
|||||||
|
|
||||||
// For each letter in the short arg, except the last one
|
// For each letter in the short arg, except the last one
|
||||||
for (i, letter) in letters.iter().copied().enumerate() {
|
for (i, letter) in letters.iter().copied().enumerate() {
|
||||||
// Safety: this loop only runs when len >= 1
|
// Safety: this loop only runs when len >= 1, so this subtraction is safe
|
||||||
let is_last_letter = i == letters.len() - 1;
|
let is_last_letter = i == letters.len() - 1;
|
||||||
|
|
||||||
let flag_info = short_flags_info.get(&letter).unwrap_or_else(|| {
|
let flag_info = short_flags_info.get(&letter).unwrap_or_else(|| {
|
||||||
@ -149,16 +149,15 @@ pub fn filter_flags(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pop the next one
|
// pop the next one
|
||||||
let flag_argument = iter.next();
|
let flag_argument = iter.next().unwrap_or_else(|| {
|
||||||
flag_argument.unwrap_or_else(|| {
|
|
||||||
panic!(
|
panic!(
|
||||||
"USer errror: argument flag `argument_flag` came at last, but it \
|
"USer errror: argument flag `argument_flag` came at last, but it \
|
||||||
requires an argument"
|
requires an argument"
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Otherwise, insert it (TODO: grab next one and add it)
|
// Otherwise, insert it.
|
||||||
// result_flags.argument_flags.insert(flag_info.long);
|
result_flags.argument_flags.insert(flag_name, flag_argument);
|
||||||
} else {
|
} else {
|
||||||
// If it was already inserted
|
// If it was already inserted
|
||||||
if result_flags.boolean_flags.contains(flag_name) {
|
if result_flags.boolean_flags.contains(flag_name) {
|
||||||
|
@ -5,6 +5,7 @@ pub fn trim_double_hyphen(flag_text: &str) -> &str {
|
|||||||
chars.as_str()
|
chars.as_str()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Currently unused
|
||||||
/// Util function to skip the single leading short flag hyphen.
|
/// Util function to skip the single leading short flag hyphen.
|
||||||
pub fn trim_single_hyphen(flag_text: &str) -> &str {
|
pub fn trim_single_hyphen(flag_text: &str) -> &str {
|
||||||
let mut chars = flag_text.chars();
|
let mut chars = flag_text.chars();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user