aboutsummaryrefslogtreecommitdiff
path: root/arg_picker/src/arg.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-20 13:19:38 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-20 13:19:38 +0800
commit45fc8cfd6ab75ce8f91f7ea32c78f46df345ec90 (patch)
tree857c10acf94574da3942d8433db32b260cd9a65b /arg_picker/src/arg.rs
parent09a83d5013ae4d403a0c873caa6300449c8f138a (diff)
feat(arg): add into_info conversion and flag formatting helpers
- Move PickerArg-to-PickerArgInfo conversion into an `into_info` method - Add `short_flag()` and `long_flag()` methods to PickerArgInfo
Diffstat (limited to 'arg_picker/src/arg.rs')
-rw-r--r--arg_picker/src/arg.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/arg_picker/src/arg.rs b/arg_picker/src/arg.rs
index a352418..4fa21b5 100644
--- a/arg_picker/src/arg.rs
+++ b/arg_picker/src/arg.rs
@@ -1,4 +1,4 @@
-use crate::Pickable;
+use crate::{Pickable, PickerArgInfo};
use std::marker::PhantomData;
/// Represents a constraint definition for a parameter selection.
@@ -133,6 +133,35 @@ 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,
+ }
+ }
}
/// Describes the attribute (behavior) of a command-line parameter.