Struct clap_mangen::Man
source · pub struct Man { /* private fields */ }
Expand description
A manpage writer
Implementations§
source§impl Man
impl Man
Build a Man
sourcepub fn new(cmd: Command) -> Self
pub fn new(cmd: Command) -> Self
Create a new manual page.
Examples found in repository?
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
fn main() -> Result<(), std::io::Error> {
let cmd = Command::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")
.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(
Command::new("test")
.about("does testing things")
.arg(arg!(-l --list "Lists test values")),
);
Man::new(cmd).render(&mut io::stdout())
}
sourcepub fn title(self, title: impl Into<String>) -> Self
pub fn title(self, title: impl Into<String>) -> Self
Override the default man page title, written in all caps
sourcepub fn section(self, section: impl Into<String>) -> Self
pub fn section(self, section: impl Into<String>) -> Self
Override the default section this man page is placed in
Common values:
"1"
: User Commands"2"
: System Calls"3"
: C Library Functions"4"
: Devices and Special Files"5"
: File Formats and Conventions"6"
: Games et. al."7"
: Miscellanea"8"
: System Administration tools and Daemons
sourcepub fn date(self, date: impl Into<String>) -> Self
pub fn date(self, date: impl Into<String>) -> Self
Override the default date for the last non-trivial change to this man page
Dates should be written in the form YYYY-MM-DD
.
source§impl Man
impl Man
Generate ROFF output
sourcepub fn render(&self, w: &mut dyn Write) -> Result<(), Error>
pub fn render(&self, w: &mut dyn Write) -> Result<(), Error>
Render a full manual page into the writer.
If customization is needed, you can call the individual sections you want and mix them into your own ROFF content.
Examples found in repository?
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
fn main() -> Result<(), std::io::Error> {
let cmd = Command::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")
.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(
Command::new("test")
.about("does testing things")
.arg(arg!(-l --list "Lists test values")),
);
Man::new(cmd).render(&mut io::stdout())
}
sourcepub fn render_title(&self, w: &mut dyn Write) -> Result<(), Error>
pub fn render_title(&self, w: &mut dyn Write) -> Result<(), Error>
Render the title into the writer.
sourcepub fn render_name_section(&self, w: &mut dyn Write) -> Result<(), Error>
pub fn render_name_section(&self, w: &mut dyn Write) -> Result<(), Error>
Render the NAME section into the writer.
sourcepub fn render_synopsis_section(&self, w: &mut dyn Write) -> Result<(), Error>
pub fn render_synopsis_section(&self, w: &mut dyn Write) -> Result<(), Error>
Render the SYNOPSIS section into the writer.
sourcepub fn render_description_section(&self, w: &mut dyn Write) -> Result<(), Error>
pub fn render_description_section(&self, w: &mut dyn Write) -> Result<(), Error>
Render the DESCRIPTION section into the writer.
sourcepub fn render_options_section(&self, w: &mut dyn Write) -> Result<(), Error>
pub fn render_options_section(&self, w: &mut dyn Write) -> Result<(), Error>
Render the OPTIONS section into the writer.
sourcepub fn render_subcommands_section(&self, w: &mut dyn Write) -> Result<(), Error>
pub fn render_subcommands_section(&self, w: &mut dyn Write) -> Result<(), Error>
Render the SUBCOMMANDS section into the writer.
sourcepub fn render_extra_section(&self, w: &mut dyn Write) -> Result<(), Error>
pub fn render_extra_section(&self, w: &mut dyn Write) -> Result<(), Error>
Render the EXTRA section into the writer.
sourcepub fn render_version_section(&self, w: &mut dyn Write) -> Result<(), Error>
pub fn render_version_section(&self, w: &mut dyn Write) -> Result<(), Error>
Render the VERSION section into the writer.
Render the AUTHORS section into the writer.