mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 11:35:45 +00:00
oof: add error variant DuplicatedFlag
This commit is contained in:
parent
faae7c088f
commit
613074dff1
@ -14,7 +14,8 @@ pub enum OofError<'t> {
|
||||
/// User supplied an unrecognized short flag
|
||||
UnknownShortFlag(char),
|
||||
MisplacedShortArgFlagError(char),
|
||||
MissingValueToFlag(&'t Flag)
|
||||
MissingValueToFlag(&'t Flag),
|
||||
DuplicatedFlag(&'t Flag)
|
||||
}
|
||||
|
||||
impl<'t> error::Error for OofError<'t> {
|
||||
@ -39,7 +40,8 @@ impl<'t> fmt::Display for OofError<'t> {
|
||||
OofError::InvalidUnicode(flag) => write!(f, "{:?} is not valid Unicode.", flag),
|
||||
OofError::UnknownShortFlag(ch) => write!(f, "Unknown argument '-{}'", ch),
|
||||
OofError::MisplacedShortArgFlagError(ch) => write!(f, "Invalid placement of `-{}`.\nOnly the last letter in a sequence of short flags can take values.", ch),
|
||||
OofError::MissingValueToFlag(flag) => write!(f, "Flag {} takes value but none was supplied.", flag)
|
||||
OofError::MissingValueToFlag(flag) => write!(f, "Flag {} takes value but none was supplied.", flag),
|
||||
OofError::DuplicatedFlag(flag) => write!(f, "Duplicated usage of {}.", flag),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ pub fn filter_flags(
|
||||
if flag_info.takes_value {
|
||||
// If it was already inserted
|
||||
if result_flags.argument_flags.contains_key(flag_name) {
|
||||
panic!("User error: duplicated, found this flag TWICE!");
|
||||
return Err(OofError::DuplicatedFlag(flag_info));
|
||||
}
|
||||
|
||||
// pop the next one
|
||||
@ -156,7 +156,7 @@ pub fn filter_flags(
|
||||
} else {
|
||||
// If it was already inserted
|
||||
if result_flags.boolean_flags.contains(flag_name) {
|
||||
panic!("User error: duplicated, found this flag TWICE!");
|
||||
return Err(OofError::DuplicatedFlag(flag_info));
|
||||
}
|
||||
// Otherwise, insert it
|
||||
result_flags.boolean_flags.insert(flag_name);
|
||||
@ -176,7 +176,7 @@ pub fn filter_flags(
|
||||
if flag_info.takes_value {
|
||||
// If it was already inserted
|
||||
if result_flags.argument_flags.contains_key(&flag_name) {
|
||||
panic!("User error: duplicated, found this flag TWICE!");
|
||||
return Err(OofError::DuplicatedFlag(flag_info));
|
||||
}
|
||||
|
||||
let flag_argument = iter.next().unwrap_or_else(|| {
|
||||
@ -189,7 +189,7 @@ pub fn filter_flags(
|
||||
} else {
|
||||
// If it was already inserted
|
||||
if result_flags.boolean_flags.contains(&flag_name) {
|
||||
panic!("User error: duplicated, found this flag TWICE!");
|
||||
return Err(OofError::DuplicatedFlag(flag_info));
|
||||
}
|
||||
// Otherwise, insert it
|
||||
result_flags.boolean_flags.insert(&flag_name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user