Reputation: 4324
I have a program that runs a custom command, lets say it is called cmd
, and the program can take custom arguments for that command. So, using structopt
crate I can created a struct
that looks like the following:
#[derive(StructOpt)]
struct Args {
#[structopt(short, long)
custom: String
}
So, when running the program with the following example:
cargo run -- -c "-e env"
-e env
is an argument for the cmd
command that will be run as a child process.
But, the program fails with the following error:
error: Found argument '-e env' which wasn't expected, or isn't valid in this context
I already checked this answer, but it is not the same case as mine.
What I tried is the following:
&str
back into String
fn parse_custom_command(custom: &str) -> Result<String, ParseCharError> {
custom.split_whitespace().collect()
}
#[derive(StructOpt)]
struct Args {
#[structopt(short, long, parse(try_from_str = parse_custom_command)]
custom: String
}
But, I get the same error.
I know that is hard to tell the parser that -e
is not an option in the struct, I think it needs to know at lease one of two:
-t
is the last argument, so take whatever is after"
of the -t
argumentHow can I solve this issue ?
Upvotes: 1
Views: 73