pub struct Arg { /* private fields */ }std only.Expand description
A single argument a command accepts.
Build one with Arg::flag, Arg::option, or Arg::positional, then
attach it with Command::arg. The name is the key
used to read the parsed result back out of a Matches.
§Examples
use cli_forge::Arg;
let verbose = Arg::flag("verbose").short('v').help("print extra detail");
let output = Arg::option("output").short('o').required(true);
let path = Arg::positional("path").default(".");Implementations§
Source§impl Arg
impl Arg
Sourcepub fn option(name: impl Into<String>) -> Arg
pub fn option(name: impl Into<String>) -> Arg
Define a value-taking option, e.g. --output file. Accepts --name v,
--name=v, -x v, and -xv at parse time.
§Examples
use cli_forge::Arg;
let out = Arg::option("output").short('o').required(true);Sourcepub fn positional(name: impl Into<String>) -> Arg
pub fn positional(name: impl Into<String>) -> Arg
Define a positional argument, filled by bare values in order.
§Examples
use cli_forge::Arg;
let path = Arg::positional("path").default(".");Sourcepub fn short(self, short: char) -> Arg
pub fn short(self, short: char) -> Arg
Set a one-letter short form (-x). Ignored for positionals.
Sourcepub fn long(self, long: impl Into<String>) -> Arg
pub fn long(self, long: impl Into<String>) -> Arg
Override the long form (--name). Defaults to the argument’s name.
Ignored for positionals.
Sourcepub fn help(self, help: impl Into<String>) -> Arg
pub fn help(self, help: impl Into<String>) -> Arg
Attach help text. Surfaced by the help engine (v0.4.0); stored now so definitions are complete.
Sourcepub fn required(self, required: bool) -> Arg
pub fn required(self, required: bool) -> Arg
Require the argument. Parsing fails with
ParseError::MissingRequired if it
is absent and has no default. Has no effect on flags (a flag is simply
present or not).