mark
October 24, 2022, 9:02am
1
I am using clap's derive API:
#[derive(Parser, Debug)]
#[clap(
name = "myapp",
version,
about = "about this app"
)]
pub struct Cli {
...
}
fn get_config() -> Config {
let cli = Cli::parse();
...
}
However, I would really like to set the Cli Parser's about (or long_about) programmatically. Is this possible?
erelde
October 24, 2022, 9:05am
2
You should be able to get the Command
struct with the CommandFactory
trait derived as part of Parser
. And then add your about section and follow the docs to get back your struct .
Example
mark
October 24, 2022, 9:23am
3
I can do the first bit:
let command = Cli::command();
let _ = command.about(get_about());
But I can't work out the syntax for the second part to parse the args in the Cli struct.
erelde
October 24, 2022, 9:37am
6
Look closer at the example and your error.
You still have a Command
struct, you need to get the matches, you should call the get_matches
method of Command
.
mark
October 24, 2022, 9:40am
7
Yes, I realised I needed the get_matches()
call. Thanks again!
system
Closed
January 22, 2023, 9:41am
8
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.