-
Notifications
You must be signed in to change notification settings - Fork 6
Description
Positional argument from enum is removed in #72, and #82 add a new way for positional arguments.
There is no example for positional arguments in current code base.
Will you provide some example for this? It is hard to now how to use positional argument now.
By the way, is it possible to use enum with positional arguments in this way?
#[derive(Arguments)]
enum Arg {
#[arg("FILE")]
File(PathBuf),
#[arg("[FILE2]")]
File2(Option<PathBuf>),
#[arg("[FILES]...")]
Files(Vec<PathBuf>),
}
Optional, we also can add a positional argument with more than one file like this.
#[arg("FILES [FILES]...")]
Files(Vec<PathBuf>),
Besides, we can have a Settings::new()
and Settings::full_parse()
in the trait, so user can have all the parsed argument to build his settings.
impl Options<Arg> for Settings {
fn new(args: HashMap<String, Arg>) -> Self {
// TODO
}
fn full_parse() -> Result<Self, Error> {
let mut args = HashMap::new();
for arg in ArgumentIter::<Arg>::from_args(args).into_iter() {
// Length check, if not good we will raise error
args.insert(arg.as_key(), arg);
}
// Check required arguments
for required_arg in Arg::required() {
if !args.contains_key(required_arg) {
raise Err()
}
}
Ok(Self::new(args))
}
}
In the macro, we will panic and prompt user to have all capital charters for the macro input, implement as_key()
for the key of the HashMap, and also implement Arg::required() -> Vec<String>
to check the arguments.
In other words, Arg::File(...)
should be #[arg("FILE")]
, #[arg("[FILE]")]
, #[arg("[FILE]...")]
, or #[arg("FILE [FILE]...")]
. and it can be get args.get("FILE")
from the HashMap<String, Arg>
.
If you think this is good idea, I can move forward with this feature.