pub struct CommandSpec {Show 15 fields
pub name: String,
pub bin_name: Option<String>,
pub version: Option<String>,
pub about: String,
pub long_about: Option<String>,
pub aliases: Vec<String>,
pub usage: Vec<String>,
pub args: Vec<ArgSpec>,
pub subcommands: Vec<CommandSpec>,
pub examples: Vec<Example>,
pub sections: Vec<Section>,
pub heading_notes: Vec<HeadingNote>,
pub subcommand_heading: Option<String>,
pub subcommand_required: bool,
pub hidden: bool,
}Expand description
A command (or subcommand) and everything its documentation needs.
use rich_ext::cli_doc::{ArgSpec, CommandSpec};
let spec = CommandSpec::new("rich")
.version("1.0.0")
.about("Render files in the terminal")
.arg(ArgSpec::flag("pager").help("Page the output"))
.arg(ArgSpec::positional("resource"))
.subcommand(CommandSpec::new("config").about("Show settings"));
assert_eq!(spec.usage_lines(), vec!["rich [OPTIONS] [RESOURCE] [COMMAND]".to_string()]);Fields§
§name: String§bin_name: Option<String>The executable name, when it differs from name.
version: Option<String>§about: String§long_about: Option<String>§aliases: Vec<String>Other names a subcommand answers to.
usage: Vec<String>Explicit usage lines; one is generated from the arguments when empty.
args: Vec<ArgSpec>§subcommands: Vec<CommandSpec>§examples: Vec<Example>§sections: Vec<Section>§heading_notes: Vec<HeadingNote>§subcommand_heading: Option<String>The title of the subcommand list; None means “Commands”.
subcommand_required: boolWhether a subcommand must be given (<COMMAND> rather than
[COMMAND] in generated usage).
Hidden subcommands are left out of help, docs and completions.
Implementations§
Source§impl CommandSpec
impl CommandSpec
pub fn new(name: impl Into<String>) -> Self
pub fn bin_name(self, name: impl Into<String>) -> Self
pub fn version(self, version: impl Into<String>) -> Self
pub fn about(self, about: impl Into<String>) -> Self
pub fn long_about(self, about: impl Into<String>) -> Self
pub fn alias(self, alias: impl Into<String>) -> Self
Sourcepub fn usage(self, line: impl Into<String>) -> Self
pub fn usage(self, line: impl Into<String>) -> Self
Add an explicit usage line (without the Usage: label).
pub fn arg(self, arg: ArgSpec) -> Self
pub fn args(self, args: impl IntoIterator<Item = ArgSpec>) -> Self
pub fn subcommand(self, command: CommandSpec) -> Self
pub fn example( self, command: impl Into<String>, description: impl Into<String>, ) -> Self
pub fn section(self, title: impl Into<String>, body: impl Into<String>) -> Self
Sourcepub fn heading_note(
self,
heading: impl Into<String>,
text: impl Into<String>,
) -> Self
pub fn heading_note( self, heading: impl Into<String>, text: impl Into<String>, ) -> Self
Add a note shown under the option group titled heading.
pub fn subcommand_heading(self, heading: impl Into<String>) -> Self
pub fn subcommand_required(self, required: bool) -> Self
Sourcepub fn display_name(&self) -> &str
pub fn display_name(&self) -> &str
The name the command is invoked by: bin_name, else name.
Sourcepub fn visible_args(&self) -> impl Iterator<Item = &ArgSpec>
pub fn visible_args(&self) -> impl Iterator<Item = &ArgSpec>
The arguments that are not hidden.
Sourcepub fn visible_subcommands(&self) -> impl Iterator<Item = &CommandSpec>
pub fn visible_subcommands(&self) -> impl Iterator<Item = &CommandSpec>
The subcommands that are not hidden.
Sourcepub fn find_subcommand(&self, name: &str) -> Option<&CommandSpec>
pub fn find_subcommand(&self, name: &str) -> Option<&CommandSpec>
The subcommand called (or aliased) name.
Sourcepub fn groups(&self) -> Vec<(String, Vec<&ArgSpec>)>
pub fn groups(&self) -> Vec<(String, Vec<&ArgSpec>)>
The visible option groups in first-seen order, each with its arguments. Positionals without a heading form a trailing “Arguments” group.
Sourcepub fn note_for(&self, heading: &str) -> Option<&str>
pub fn note_for(&self, heading: &str) -> Option<&str>
The note for the group titled heading, if any.
Sourcepub fn usage_lines(&self) -> Vec<String>
pub fn usage_lines(&self) -> Vec<String>
The usage lines, generated when none were given.
Sourcepub fn usage_lines_as(&self, prefix: &str) -> Vec<String>
pub fn usage_lines_as(&self, prefix: &str) -> Vec<String>
The usage lines with prefix (such as rich config) as the command.
Explicit lines starting with this command’s name get the prefix
substituted; generated lines are
prefix [OPTIONS] <REQUIRED OPTIONS> [POSITIONALS] [COMMAND].
Sourcepub fn switch_names(&self) -> Vec<String>
pub fn switch_names(&self) -> Vec<String>
Every visible -s/--long spelling, for suggestions.
Sourcepub fn subcommand_names(&self) -> Vec<String>
pub fn subcommand_names(&self) -> Vec<String>
Every visible subcommand name and alias, for suggestions.
Source§impl CommandSpec
impl CommandSpec
Sourcepub fn from_clap(cmd: &Command) -> CommandSpec
pub fn from_clap(cmd: &Command) -> CommandSpec
The spec of a clap command and its subcommands, including clap’s
generated --help/--version flags and help subcommand.
Maps long, short and visible aliases, value names, possible values
(with their help), value hints, defaults, environment variables, help
headings, hidden, required and positional arguments; Count and
Append actions (or more than one value) make an argument multiple.
about, long_about, version, an overridden usage and the
subcommand heading carry over; after_help (else after_long_help)
becomes an untitled section.
Trait Implementations§
Source§impl Clone for CommandSpec
impl Clone for CommandSpec
Source§impl Debug for CommandSpec
impl Debug for CommandSpec
Source§impl Default for CommandSpec
impl Default for CommandSpec
impl Eq for CommandSpec
Source§impl PartialEq for CommandSpec
impl PartialEq for CommandSpec
impl StructuralPartialEq for CommandSpec
Auto Trait Implementations§
impl Freeze for CommandSpec
impl RefUnwindSafe for CommandSpec
impl Send for CommandSpec
impl Sync for CommandSpec
impl Unpin for CommandSpec
impl UnsafeUnpin for CommandSpec
impl UnwindSafe for CommandSpec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.