It would be great to have a way to save unknow args into a Vec<> or slice. For example, an Arg::with_name() option, e.g. Arg::with_name('unknow').unknow_args() or something like this.
Maybe it could be that instead of calling get_matches() on the arg list, add a get_know_matches() that returns a tuple, the first element being what would be get_matches() and the second a vector of the unknow args... Something like Python's argparse:
args, unknown = parser.parse_known_args()
let (matches, unknow_matches) = App::new("myprog")
.version("0.1")
.author("You <[email protected]>")
.about("Something about your program")
.arg(Arg::with_name("debug")
.short("d")
.multiple(true)
.help("Turn debugging information on"))
.arg(Arg::with_name("quiet")
.short("q")
.long("shut-up")
.help("Shut up"))
.get_know_matches();
And then, if you call myprog -d --something, you have in matches the normal clap behaviour, and in unknow_matches a vector containg '--something'
I don't know if I'm explaining it well, as English is not my primary language.
EDIT: Save unknow in vector or slice instead of ignoring them
The reason for this is that i'm building a program that has "subargs" (e.g. myprogram -Xh is the message help for myprogram -X, but not the same help as myprogram -Yh or myprogram -h.) I can build this by adding -X and -Y arguments, and run another function based on which arg was used, but clap needs to know all arguments, and that's why this would be nice.
I found this: https://github.com/clap-rs/clap/issues/1361 It's exactly what I was looking for... maybe we should focus on that issue.
I could still quite use this: I want to be able to pass-through the args to a specific subcommand to a child process, ignoring all the direct args to the subcommand itself.
It would be useful for me too
I just found out how to do it! I used: AppSettings::TrailingVarArg, AppSettings::AllowLeadingHyphen
I did it with structopt but you can translate to the clap equivalent.
Most helpful comment
I could still quite use this: I want to be able to pass-through the args to a specific subcommand to a child process, ignoring all the direct args to the subcommand itself.