pub struct FlagSpec {
pub name: &'static str,
pub short: Option<char>,
pub doc: &'static str,
pub env: Option<&'static str>,
}Expand description
Specification for Flag.
Note that noargs does not support flags with only short names.
Fields§
§name: &'static strFlag long name (usually kebab-case).
short: Option<char>Flag short name.
doc: &'static strDocumentation.
env: Option<&'static str>Environment variable name.
If a non-empty value is set to this variable, this flag is considered to be set.
Implementations§
Source§impl FlagSpec
impl FlagSpec
Sourcepub const fn new(name: &'static str) -> Self
pub const fn new(name: &'static str) -> Self
Makes an FlagSpec instance with a specified name (equivalent to noargs::flag(name)).
Sourcepub const fn short(self, name: char) -> Self
pub const fn short(self, name: char) -> Self
Updates the value of FlagSpec::short.
Sourcepub const fn doc(self, doc: &'static str) -> Self
pub const fn doc(self, doc: &'static str) -> Self
Updates the value of FlagSpec::doc.
Sourcepub const fn env(self, variable_name: &'static str) -> Self
pub const fn env(self, variable_name: &'static str) -> Self
Updates the value of FlagSpec::env.
Sourcepub fn take(self, args: &mut RawArgs) -> Flag
pub fn take(self, args: &mut RawArgs) -> Flag
Takes the first Flag instance that satisfies this specification from the raw arguments.
Sourcepub fn take_help(self, args: &mut RawArgs) -> Flag
pub fn take_help(self, args: &mut RawArgs) -> Flag
Similar to FlagSpec::take(), but updates the help-related metadata of args when the flag is present.
Specifically, the following code is executed:
args.metadata_mut().help_mode = true;
args.metadata_mut().help_flag_name = Some(flag.spec().name);
if matches!(flag, Flag::Long { .. }) {
args.metadata_mut().full_help = true;
}Trait Implementations§
impl Copy for FlagSpec
impl Eq for FlagSpec
impl StructuralPartialEq for FlagSpec
Auto Trait Implementations§
impl Freeze for FlagSpec
impl RefUnwindSafe for FlagSpec
impl Send for FlagSpec
impl Sync for FlagSpec
impl Unpin for FlagSpec
impl UnwindSafe for FlagSpec
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
Mutably borrows from an owned value. Read more