Expand description
Turn a struct into arguments for a Command
. See the
derive macro for options you can pass in.
#[derive(Arg)]
struct BasicArgs<'a> {
#[arg(position = 1)]
str_ref: &'a str,
#[arg(variadic)]
number: u8,
#[arg(rename = "p", short)]
path: PathBuf,
opt_skipped: Option<String>,
#[arg(position = 0)]
opt_present: Option<&'static str>,
false_arg: bool,
true_arg: bool,
#[arg(skip)]
_skipped_arg: *const u8,
empty_collection: Vec<&'a Path>,
full_collection: Vec<String>,
}
let args = BasicArgs {
str_ref: "hello",
number: 42,
path: Path::new("world").to_owned(),
opt_skipped: None,
opt_present: Some("present".into()),
false_arg: false,
true_arg: true,
_skipped_arg: ptr::null(),
empty_collection: Vec::new(),
full_collection: vec!["a".into(), "b".into()],
};
let mut command = Command::new("foo");
command.add_arg_set(&args);
let resulting_args = command.get_args().collect::<Vec<_>>();
assert_eq!(&resulting_args[..], &[
"-p",
"world",
"--true_arg",
"--full_collection",
"a",
"b",
"present",
"hello",
"42",
]);
Support for async-std
and tokio
can be enabled via their respective features.
Modules§
Traits§
- Arg
- An argument that can be passed to an
ArgConsumer
such as aCommand
. - ArgConsumer
- An
Arg
consumer
Type Aliases§
- Collected
Args Arg
s collected in aVec
Derive Macros§
- Arg
- Derive the
Arg
trait.