pub struct Metadata {
pub app_name: &'static str,
pub app_description: &'static str,
pub help_flag_name: Option<&'static str>,
pub help_mode: bool,
pub full_help: bool,
pub is_valid_flag_chars: fn(&str) -> bool,
}Expand description
Metadata of RawArgs.
Fields§
§app_name: &'static strApplication name (e.g., env!("CARGO_PKG_NAME")).
app_description: &'static strApplication description (e.g., env!("CARGO_PKG_DESCRIPTION")).
help_flag_name: Option<&'static str>Flag name for help (default: Some("help")).
help_mode: boolWhen enabled, the following help mode behaviors apply:
RawArgs::finish()will returnOk(Some(help_text))if successful- Only default and example values will be used when calling
ArgSpec::take()orOptSpec::take()
full_help: boolIf true, a full help text will be displayed.
is_valid_flag_chars: fn(&str) -> boolPredicate function to determine if a string contains only valid flag characters.
This function is used when parsing short flags to distinguish between:
- Multiple flags (e.g.,
-abcwhere each character is a flag) - Options with concatenated values (e.g.,
-khellowhere ‘k’ is an option and “hello” is its value)
The default implementation accepts only ASCII alphabetic characters, which prevents
ambiguity in parsing. For example, with -khello world, the presence of space and
non-alphabetic characters indicates this is an option with a concatenated value rather
than multiple flags.
§Example: Only accept flags actually defined by the app
use noargs::{raw_args, flag};
let mut args = raw_args();
// Define the valid short flags for your app
const VALID_FLAGS: &[char] = &['h', 'v', 'q', 'd'];
// Only allow characters that correspond to actual flags in your app
args.metadata_mut().is_valid_flag_chars = |chars| {
chars.chars().all(|c| VALID_FLAGS.contains(&c))
};
// Now only -h, -v, -q, -d and their combinations (like -hv, -vd) are valid
// Anything else like -khello be treated as an option with concatenated value
let help_flag = flag("help").short('h').take(&mut args);
let verbose_flag = flag("verbose").short('v').take(&mut args);
let quiet_flag = flag("quiet").short('q').take(&mut args);
let debug_flag = flag("debug").short('d').take(&mut args);Trait Implementations§
impl Copy for Metadata
impl Eq for Metadata
impl StructuralPartialEq for Metadata
Auto Trait Implementations§
impl Freeze for Metadata
impl RefUnwindSafe for Metadata
impl Send for Metadata
impl Sync for Metadata
impl Unpin for Metadata
impl UnwindSafe for Metadata
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