Skip to main content

ConfigCommand

Struct ConfigCommand 

Source
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

Source

pub fn new() -> Self

Create a new ConfigCommand with default names matching ConfigArgs.

Source

pub fn list_name(self, name: impl Into<String>) -> Self

Rename the list subcommand.

Source

pub fn gen_name(self, name: impl Into<String>) -> Self

Rename the gen subcommand.

Source

pub fn schema_name(self, name: impl Into<String>) -> Self

Rename the schema subcommand.

Source

pub fn get_name(self, name: impl Into<String>) -> Self

Rename the get subcommand.

Source

pub fn set_name(self, name: impl Into<String>) -> Self

Rename the set subcommand.

Source

pub fn unset_name(self, name: impl Into<String>) -> Self

Rename the unset subcommand.

Source

pub fn scope_long(self, name: impl Into<String>) -> Self

Rename the --scope flag.

Source

pub fn output_long(self, name: impl Into<String>) -> Self

Rename the --output flag on the gen subcommand.

Source

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.

Source

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").

Source

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.

Trait Implementations§

Source§

impl Default for ConfigCommand

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.