pub struct ConfigCommand { /* private fields */ }Expand description
Runtime-configurable alternative to ConfigArgs for apps that need
to rename subcommands or flags to avoid conflicts.
Both ConfigArgs (derive) and ConfigCommand (builder) produce
ConfigAction, so all downstream logic is shared.
§Example
use clapfig::ConfigCommand;
let config_cmd = ConfigCommand::new()
.scope_long("target") // rename --scope to --target
.gen_name("template"); // rename "gen" to "template"
let app = Cli::command()
.subcommand(config_cmd.as_command("settings"));
let matches = app.get_matches();
if let Some(("settings", sub)) = matches.subcommand() {
let action = config_cmd.parse(sub)?;
builder.handle_and_print(&action)?;
}Implementations§
Source§impl ConfigCommand
impl ConfigCommand
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ConfigCommand with default names matching ConfigArgs.
Sourcepub fn schema_name(self, name: impl Into<String>) -> Self
pub fn schema_name(self, name: impl Into<String>) -> Self
Rename the schema subcommand.
Sourcepub fn unset_name(self, name: impl Into<String>) -> Self
pub fn unset_name(self, name: impl Into<String>) -> Self
Rename the unset subcommand.
Sourcepub fn scope_long(self, name: impl Into<String>) -> Self
pub fn scope_long(self, name: impl Into<String>) -> Self
Rename the --scope flag.
Sourcepub fn output_long(self, name: impl Into<String>) -> Self
pub fn output_long(self, name: impl Into<String>) -> Self
Rename the --output flag on the gen subcommand.
Sourcepub fn output_short(self, short: Option<char>) -> Self
pub fn output_short(self, short: Option<char>) -> Self
Set or disable the short flag for --output (default: Some('o')).
Pass None to remove the short flag entirely.
Sourcepub fn as_command(&self, name: &str) -> Command
pub fn as_command(&self, name: &str) -> Command
Build a clap::Command with the configured names.
The name parameter sets the top-level subcommand name
(e.g. "config", "settings").
Sourcepub fn parse(&self, matches: &ArgMatches) -> Result<ConfigAction, ClapfigError>
pub fn parse(&self, matches: &ArgMatches) -> Result<ConfigAction, ClapfigError>
Extract a ConfigAction from parsed ArgMatches.
Bare invocation (no subcommand) maps to ConfigAction::List,
matching the behavior of ConfigArgs::into_action.