I have a command line to search a word inside a file. I'm using StructOpt to get the word that the user wants to search.
#[derive(Debug, StructOpt)]
pub struct Command {
pub word_to_search: Option<String>,
}
The problem comes when you write something like command -a
. I know that the library is trying to do something with -a
and there is no -a
in the struct
, so I tried: command "-a"
but it displays:
error: Found argument '-a' which wasn't expected, or isn't valid in this context
Is there a way to pass special characters like -a
and retrieve the information (-a
) using StructOpt?
You don't need to change anything, you only have to call the command using
command -- -a
. The double dash is used to indicate that it's the end of options and in this case the rest is the word that the user is looking for.