aboutsummaryrefslogtreecommitdiff
path: root/mingling_picker/src/picker.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-16 03:27:19 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-16 03:27:19 +0800
commit0bded81c4e205e387998bf64087acfc39cf70e3e (patch)
tree48c5da0aa8c8f27f1f2465569c5f0a2291a3127b /mingling_picker/src/picker.rs
parentf11b53d5c7fdfc090aaca49f83a92876568e119b (diff)
feat(picker): add from_args and from_args_skip constructors
Diffstat (limited to 'mingling_picker/src/picker.rs')
-rw-r--r--mingling_picker/src/picker.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/mingling_picker/src/picker.rs b/mingling_picker/src/picker.rs
index acdb8b5..d065891 100644
--- a/mingling_picker/src/picker.rs
+++ b/mingling_picker/src/picker.rs
@@ -24,6 +24,31 @@ pub struct Picker<'a, Route = ()> {
args: PickerArgs<'a>,
}
+impl<'a> Picker<'a> {
+ /// Creates a new `Picker` from the command-line arguments (excluding the program name).
+ ///
+ /// This is equivalent to calling `std::env::args().skip(1)`, which
+ /// collects all arguments passed to the program except the first one
+ /// (the executable path).
+ pub fn from_args() -> Picker<'a, ()> {
+ Self::from_args_skip(1)
+ }
+
+ /// Creates a new `Picker` from the command-line arguments, skipping the
+ /// first `skip` entries.
+ ///
+ /// This method is useful when you want more control over which arguments
+ /// are included. For example, pass `skip = 2` to skip both the program
+ /// name and the first argument.
+ pub fn from_args_skip(skip: usize) -> Picker<'a, ()> {
+ let args = std::env::args().skip(skip).collect::<Vec<String>>();
+ Picker {
+ route_phantom: PhantomData,
+ args: PickerArgs::Owned(args),
+ }
+ }
+}
+
/// Internal arguments of Picker
///
/// - `Slice` - borrowed slice of string slices