Skip to content

Can I generate a string of help messages for derived commands? #5466

Answered by epage
jeffka11 asked this question in Q&A
Discussion options

You must be logged in to vote

It would be something like:

#[derive(Parser)]
struct Cli {
}

fn main() {
    use clap::CommandFactory as _;
    let mut command = Cli::command();
    command.build();
    for sub in command.get_subcommands() {
        let styled_str = sub.render_help();
    }
}

See

You can get the plaintext output of styled_str or you can render it to ANSI escape codes. I don't have an HTML converter for that but I do have anstyle-svg for SVG. If you want to generate styled HTML, you could mimic what anstyle-svg does. I might be open to it being contributed back to the a…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jeffka11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants