pub enum UnknownFlags {
Value,
Error,
}Expand description
What to do with a token that looks like a flag but names no declared flag.
The default is UnknownFlags::Value, which is where this parser parts
company with clap, argparse, commander, oclif v2+, and POSIX getopt — all of
which reject the token. The reason is that those parse their own argv, where
a dash-word can only be a flag or a typo, while a usage spec is also used to
parse things whose flags it does not own:
- a shell script run through
usage exec, forwarding options to a tool it wraps - a task’s arguments, where the task script is the authority on what it accepts
- a completion, asked about a command line that is still being typed
In all three, a dash-word the spec has not heard of is far more likely to be data in transit than a mistake, and rejecting it would break the wrapper for everyone who did not enumerate the flags of the program behind it.
The cost is real and worth stating: a misspelled --hekp becomes an argument
instead of an error, and whether it does depends on whether a positional is
free to take it. A CLI that owns all of its flags — as opposed to forwarding
them — should say UnknownFlags::Error and get the stricter reading.
Variants§
Value
Offer the token to the positional arguments, like any other word. If none can take it, it is an unexpected argument — the same error an extra word would produce.
Error
Reject the token. A CLI whose flags are all its own gets typo detection
this way, at the price of needing -- to pass a value that begins with a
dash.
Implementations§
Trait Implementations§
Source§impl Clone for UnknownFlags
impl Clone for UnknownFlags
Source§fn clone(&self) -> UnknownFlags
fn clone(&self) -> UnknownFlags
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for UnknownFlags
Source§impl Debug for UnknownFlags
impl Debug for UnknownFlags
Source§impl Default for UnknownFlags
impl Default for UnknownFlags
Source§fn default() -> UnknownFlags
fn default() -> UnknownFlags
Source§impl Display for UnknownFlags
impl Display for UnknownFlags
impl Eq for UnknownFlags
Source§impl FromStr for UnknownFlags
impl FromStr for UnknownFlags
Source§impl PartialEq for UnknownFlags
impl PartialEq for UnknownFlags
Source§impl Serialize for UnknownFlags
impl Serialize for UnknownFlags
impl StructuralPartialEq for UnknownFlags
Auto Trait Implementations§
impl Freeze for UnknownFlags
impl RefUnwindSafe for UnknownFlags
impl Send for UnknownFlags
impl Sync for UnknownFlags
impl Unpin for UnknownFlags
impl UnsafeUnpin for UnknownFlags
impl UnwindSafe for UnknownFlags
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more