-
I use the derive feature to create an object with subcommands. I also have a web page, where I'd like to display the help command for the object and each subcommand. Is there a way to generate the help messages as strings so I can print them on the web page? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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 |
Beta Was this translation helpful? Give feedback.
It would be something like:
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 whatanstyle-svg
does. I might be open to it being contributed back to thea…