Skip to main content

CliConfig

Struct CliConfig 

Source
pub struct CliConfig {
Show 24 fields pub name: String, pub short: String, pub long: Option<String>, pub build: BuildInfo, pub app_id: String, pub default_auth_provider: Option<String>, pub modules: Vec<Module>, pub commands: Vec<RuntimeCommandSpec>, pub guides: Vec<GuideEntry>, pub views: Vec<HumanViewDef>, pub auth_providers: Vec<Arc<dyn AuthProvider>>, pub authz: Option<Arc<dyn Authorizer>>, pub auditor: Option<Arc<dyn Auditor>>, pub activity: Option<Arc<dyn ActivityEmitter>>, pub init_deps: Option<InitDeps>, pub register_flags: Option<RegisterFlags>, pub apply_flags: Option<ApplyFlags>, pub pre_run: Option<PreRun>, pub meta_resolver: Option<ResolveMeta>, pub on_shutdown: Option<OnShutdown>, pub extra_search_docs: Option<ExtraSearchDocs>, pub root_next_actions: Option<RootNextActions>, pub admin_category: Option<String>, pub argv0_routes: BTreeMap<String, Argv0Route>,
}
Expand description

Declarative configuration for a CLI application.

Use CliConfig::new for the common path and chain with_* methods for modules, auth providers, guides, views, and lifecycle hooks. Direct struct literals remain available for advanced setup and tests.

Fields§

§name: String

Root command name shown in usage output.

§short: String

One-line root command description.

§long: Option<String>

Optional longer root command description. Defaults to short.

§build: BuildInfo

Version/build metadata for --version.

§app_id: String

Application id stored in middleware and output metadata.

§default_auth_provider: Option<String>

Fallback auth provider when a command does not select one explicitly.

§modules: Vec<Module>

Domain modules mounted under the root command.

§commands: Vec<RuntimeCommandSpec>

Additional top-level runtime commands.

§guides: Vec<GuideEntry>

Global guide entries mounted under guide.

§views: Vec<HumanViewDef>

Global human output views.

§auth_providers: Vec<Arc<dyn AuthProvider>>

Providers registered before command execution starts.

§authz: Option<Arc<dyn Authorizer>>

Optional authorization gatekeeper injected into middleware.

§auditor: Option<Arc<dyn Auditor>>

Optional audit recorder injected into middleware.

§activity: Option<Arc<dyn ActivityEmitter>>

Optional activity event sink injected into middleware.

§init_deps: Option<InitDeps>

Optional late initializer for runtime dependencies.

§register_flags: Option<RegisterFlags>

Optional hook for adding application-specific global flags.

§apply_flags: Option<ApplyFlags>

Optional hook for applying parsed application-specific flags.

§pre_run: Option<PreRun>

Optional hook run before executable commands and built-ins.

§meta_resolver: Option<ResolveMeta>

Optional hook for global command metadata adjustments.

§on_shutdown: Option<OnShutdown>

Optional hook called after each run.

§extra_search_docs: Option<ExtraSearchDocs>

Optional root-scope search document provider.

§root_next_actions: Option<RootNextActions>

Optional provider for the bare-root suggested next actions.

§admin_category: Option<String>

Name of the admin help category. The engine files its built-in auth command under this heading; apps should use the same name for their own admin modules (e.g. godaddy’s env). When unset, defaults to "Admin"; set it to match a consumer’s own taxonomy (e.g. gdx’s “Administration”).

§argv0_routes: BTreeMap<String, Argv0Route>

Alternative argv[0] names this binary may be invoked as, mapped to the behavior the engine should take (busybox/git-style multi-call dispatch).

Keyed by the bare alternative name (no path, no extension). Empty by default, in which case argv0 dispatch is inert and behavior is identical to a binary that never opted in. Populate via CliConfig::with_argv0_alias and CliConfig::with_argv0_personality.

Implementations§

Source§

impl CliConfig

Source

pub fn new( name: impl Into<String>, short: impl Into<String>, app_id: impl Into<String>, ) -> Self

Creates the minimum useful CLI configuration.

Source

pub fn with_long(self, long: impl Into<String>) -> Self

Sets root long help text.

Source

pub fn with_build(self, build: BuildInfo) -> Self

Sets build metadata used by --version.

Source

pub fn with_default_auth_provider(self, provider: impl Into<String>) -> Self

Sets the fallback auth provider for commands that do not name one.

Source

pub fn with_module(self, module: Module) -> Self

Adds one domain module.

Source

pub fn with_modules(self, modules: impl IntoIterator<Item = Module>) -> Self

Adds several domain modules.

Source

pub fn with_command(self, command: RuntimeCommandSpec) -> Self

Adds a top-level runtime command outside a module.

Source

pub fn with_guide(self, guide: GuideEntry) -> Self

Adds one global guide.

Source

pub fn with_guides(self, guides: impl IntoIterator<Item = GuideEntry>) -> Self

Adds several global guides.

Source

pub fn with_view(self, view: HumanViewDef) -> Self

Adds one global human view.

Source

pub fn with_auth_provider(self, provider: Arc<dyn AuthProvider>) -> Self

Registers one auth provider.

Source

pub fn with_authz(self, authz: Arc<dyn Authorizer>) -> Self

Sets the authorization gatekeeper.

Source

pub fn with_auditor(self, auditor: Arc<dyn Auditor>) -> Self

Sets the audit recorder.

Source

pub fn with_activity(self, activity: Arc<dyn ActivityEmitter>) -> Self

Sets the activity event sink.

Source

pub fn with_init_deps(self, init_deps: InitDeps) -> Self

Sets the late dependency initializer.

Source

pub fn with_register_flags(self, register_flags: RegisterFlags) -> Self

Sets the application-specific global flag registration hook.

Source

pub fn with_apply_flags(self, apply_flags: ApplyFlags) -> Self

Sets the application-specific parsed flag application hook.

Source

pub fn with_pre_run(self, pre_run: PreRun) -> Self

Sets the pre-run hook.

Source

pub fn with_meta_resolver(self, meta_resolver: ResolveMeta) -> Self

Sets the command metadata resolver hook.

Source

pub fn with_on_shutdown(self, on_shutdown: OnShutdown) -> Self

Sets the shutdown hook.

Source

pub fn with_extra_search_docs(self, extra_search_docs: ExtraSearchDocs) -> Self

Sets the provider for additional root-scope search documents.

Source

pub fn with_root_next_actions(self, root_next_actions: RootNextActions) -> Self

Sets the provider for the bare-root suggested next actions.

Source

pub fn with_admin_category(self, category: impl Into<String>) -> Self

Sets the name of the admin help category. The engine files the built-in auth command there; apps should use the same name for their own admin modules (e.g. godaddy’s env). Optional: defaults to "Admin".

Source

pub fn with_argv0_alias( self, name: impl Into<String>, command_path: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Registers an alternative argv[0] name that acts as a shortcut to a command path on this same CLI.

When the binary is invoked under name (via symlink, hardlink, copy, or the hidden argv0 command), the engine behaves as if the user had typed command_path followed by the real argument tail, routed through the normal command tree. For example:

use cli_engine::CliConfig;

// Invoking the binary as `pl --team platform` runs `project list --team platform`.
let config = CliConfig::new("my-cli", "Team CLI", "my-cli")
    .with_argv0_alias("pl", ["project", "list"]);

name must be a simple token: non-empty and composed only of ASCII letters, digits, -, or _ (no dots, spaces, path separators, or shell metacharacters), and it must differ from the CLI’s own name. These are debug-asserted. The restriction keeps the name usable as a link/shim filename and an argv[0] basename (which is matched with its extension stripped, so a dot would break matching).

Source

pub fn with_argv0_personality( self, name: impl Into<String>, build: impl Fn() -> CliConfig + Send + Sync + 'static, ) -> Self

Registers an alternative argv[0] name that runs an entirely separate CLI application.

When the binary is invoked under name, the engine builds a fresh CliConfig from build and runs that application instead — its own root name, commands, flags, and auth. The closure runs lazily, only when the route is dispatched, so unused personalities cost nothing. The personality presents the name from its own CliConfig in help and usage output.

use cli_engine::CliConfig;

let config = CliConfig::new("my-cli", "Team CLI", "my-cli")
    .with_argv0_personality("legacy-tool", || {
        CliConfig::new("legacy-tool", "Legacy compatibility shim", "legacy-tool")
    });

name follows the same contract as CliConfig::with_argv0_alias: a simple [A-Za-z0-9_-] token, differing from the CLI’s own name (debug-asserted).

Trait Implementations§

Source§

impl Clone for CliConfig

Source§

fn clone(&self) -> CliConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CliConfig

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CliConfig

Source§

fn default() -> CliConfig

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more