mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 15:22:30 +00:00
0b045f5d0d
This is an initial implementation with plenty of room to grow, including - Allowing pulling out a subset of the generated man page for greater customization - Subcommand handling - Extra sections - Consolidate argument formatter after #2914 Fixes #552
40 lines
1.4 KiB
Rust
40 lines
1.4 KiB
Rust
use clap::{arg, App};
|
|
use clap_man::generate_manpage;
|
|
use std::io;
|
|
|
|
// Run this example as `cargo run --example man | man -l -`.
|
|
|
|
fn main() -> Result<(), std::io::Error> {
|
|
let mut app = App::new("myapp")
|
|
.version("1.0")
|
|
.author("Kevin K. <kbknapp@gmail.com>:Ola Nordmann <old@nordmann.no>")
|
|
.about("Does awesome things")
|
|
.long_about(
|
|
"With a longer description to help clarify some things.
|
|
|
|
And a few newlines.",
|
|
)
|
|
.after_help("This is an extra section added to the end of the manpage.")
|
|
.after_long_help("With even more text added.")
|
|
.arg(
|
|
arg!(-c --config <FILE> "Sets a custom config file")
|
|
.long_help("Some more text about how to set a custom config file")
|
|
.required(false)
|
|
.takes_value(true)
|
|
.default_value("config.toml")
|
|
.env("CONFIG_FILE"),
|
|
)
|
|
.arg(arg!([output] "Sets an output file").default_value("result.txt"))
|
|
.arg(
|
|
arg!(-d --debug ... "Turn debugging information on")
|
|
.env("DEBUG_ON")
|
|
.hide_env(true),
|
|
)
|
|
.subcommand(
|
|
App::new("test")
|
|
.about("does testing things")
|
|
.arg(arg!(-l --list "Lists test values")),
|
|
);
|
|
|
|
generate_manpage(&mut app, &mut io::stdout())
|
|
}
|