diff options
Diffstat (limited to 'arg_picker/src/arg.rs')
| -rw-r--r-- | arg_picker/src/arg.rs | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/arg_picker/src/arg.rs b/arg_picker/src/arg.rs index a352418..32824ea 100644 --- a/arg_picker/src/arg.rs +++ b/arg_picker/src/arg.rs @@ -1,4 +1,4 @@ -use crate::Pickable; +use crate::{Pickable, PickerArgInfo, parselib::ParserStyle}; use std::marker::PhantomData; /// Represents a constraint definition for a parameter selection. @@ -133,6 +133,51 @@ where self.positional = positional; self } + + /// Converts this `PickerArg` into a `PickerArgInfo` value. + /// + /// This is a convenience method equivalent to calling `PickerArgInfo::from(self)`. + pub fn into_info(self) -> PickerArgInfo<'a> { + let value = self; + let (long, alias) = match value.full.len() { + 0 => (None, None), + _ => { + let long = Some(value.full[0]); + let alias = if value.full.len() > 1 { + Some(value.full[1..].to_vec()) + } else { + None + }; + (long, alias) + } + }; + + PickerArgInfo { + short: value.short, + long, + alias, + positional: value.positional, + optional: false, + multi: false, + is_flag: false, + } + } +} + +impl<'a, Type> From<PickerArg<'a, Type>> for Vec<String> +where + Type: Pickable<'a>, +{ + fn from(value: PickerArg<'a, Type>) -> Self { + let mut result = Vec::new(); + let info = PickerArgInfo::from(value); + let possible_flags = + crate::parselib::build_possible_flags(ParserStyle::global_style(), &info); + for flag in possible_flags { + result.push(flag); + } + result + } } /// Describes the attribute (behavior) of a command-line parameter. |
