pub struct Command { /* private fields */ }std only.Expand description
One node in the command tree.
Build with Command::new and refine with the chaining methods. Attach a
run handler to do the work, arg to accept
input, and subcommand to nest.
§Examples
use cli_forge::{Arg, Command};
let build = Command::new("build")
.about("compile the project")
.arg(Arg::flag("release").short('r'))
.run(|m| {
let _ = m.flag("release");
});Implementations§
Source§impl Command
impl Command
Sourcepub fn new(name: impl Into<String>) -> Command
pub fn new(name: impl Into<String>) -> Command
Create a command with the given invocation name.
§Examples
use cli_forge::Command;
let cmd = Command::new("init");Sourcepub fn alias(self, alias: impl Into<String>) -> Command
pub fn alias(self, alias: impl Into<String>) -> Command
Add an alternative name that also invokes this command. Chain it to add several. Aliases are shown alongside the name in help.
§Examples
use cli_forge::Command;
let cmd = Command::new("remove").alias("rm").alias("del");Sourcepub fn aliases<I, S>(self, aliases: I) -> Command
pub fn aliases<I, S>(self, aliases: I) -> Command
Add several alternative names at once.
§Examples
use cli_forge::Command;
let cmd = Command::new("remove").aliases(["rm", "del"]);Sourcepub fn about(self, text: impl Into<String>) -> Command
pub fn about(self, text: impl Into<String>) -> Command
Set the one-line description shown in help.
§Examples
use cli_forge::Command;
let cmd = Command::new("init").about("bootstrap a new project");Sourcepub fn arg(self, arg: Arg) -> Command
pub fn arg(self, arg: Arg) -> Command
Accept an argument. Add as many as the command needs; positionals are filled in the order they are added.
§Examples
use cli_forge::{Arg, Command};
let cmd = Command::new("copy")
.arg(Arg::positional("from").required(true))
.arg(Arg::positional("to").required(true))
.arg(Arg::flag("force").short('f'));Sourcepub fn subcommand(self, cmd: Command) -> Command
pub fn subcommand(self, cmd: Command) -> Command
Nest a subcommand. Subcommands compose recursively to any depth.
§Examples
use cli_forge::Command;
let remote = Command::new("remote")
.subcommand(Command::new("add"))
.subcommand(Command::new("remove"));Hide the command from generated help while leaving it invokable.
§Examples
use cli_forge::Command;
let cmd = Command::new("debug-dump").hidden(true);Sourcepub fn requires_auth(self, yes: bool) -> Command
pub fn requires_auth(self, yes: bool) -> Command
Mark the command as requiring authentication.
With the auth feature enabled, the command runs — and appears in help —
only when the app’s App::auth hook authorizes it; otherwise invoking it
yields ParseError::Unauthorized.
Without the auth feature the flag is inert (the command runs and shows
normally).
§Examples
use cli_forge::Command;
let cmd = Command::new("publish").requires_auth(true);