pub struct CommandSpec {Show 14 fields
pub name: String,
pub short: String,
pub long: Option<String>,
pub aliases: Vec<String>,
pub hidden: bool,
pub system: Option<String>,
pub default_fields: Option<String>,
pub auth: AuthRequirement,
pub auth_provider: Option<String>,
pub tier: Option<Tier>,
pub mutates: bool,
pub auth_metadata: BTreeMap<String, String>,
pub args: Vec<Arg>,
pub output_schema: Option<SchemaInfo>,
}Expand description
Declarative leaf command metadata and parser arguments.
CommandSpec intentionally keeps command metadata next to the command’s
handler. This is the primary copy/paste surface for teams adding commands.
Fields§
§name: StringLeaf command name.
short: StringOne-line command description.
long: Option<String>Optional long help text.
aliases: Vec<String>Alternate command names accepted by the parser.
Whether the command runs but is hidden from help, tree, and search.
system: Option<String>Backend/system id used in output metadata and generic error envelopes.
default_fields: Option<String>Default comma-separated field projection.
auth: AuthRequirementAuthentication requirement enforced by the engine for this command.
Defaults to AuthRequirement::Required (fail-closed). Use
auth_optional for commands that should run
logged out, or no_auth for commands that never
authenticate.
auth_provider: Option<String>Auth provider name for this command.
tier: Option<Tier>Risk tier used by authentication, authorization, and dry-run.
mutates: boolExplicit dry-run prompt marker for commands without a tier.
auth_metadata: BTreeMap<String, String>Provider-specific auth metadata.
args: Vec<Arg>Command-specific clap arguments.
output_schema: Option<SchemaInfo>Optional output schema published through --schema and help.
Implementations§
Source§impl CommandSpec
impl CommandSpec
Sourcepub fn new(name: impl Into<String>, short: impl Into<String>) -> Self
pub fn new(name: impl Into<String>, short: impl Into<String>) -> Self
Creates a command spec with the required name and one-line help.
Sourcepub fn from_args<T: Args>(
name: impl Into<String>,
short: impl Into<String>,
) -> Self
pub fn from_args<T: Args>( name: impl Into<String>, short: impl Into<String>, ) -> Self
Creates a command spec from a #[derive(clap::Args)] struct.
Extracts the argument definitions from the derive type and populates the
spec’s args list. The command name and help text are still required since
Args types do not carry those.
Sourcepub fn with_alias(self, alias: impl Into<String>) -> Self
pub fn with_alias(self, alias: impl Into<String>) -> Self
Adds one command alias.
Hides or shows this command in discovery output.
Sourcepub fn with_system(self, system: impl Into<String>) -> Self
pub fn with_system(self, system: impl Into<String>) -> Self
Sets the backend/system id for output metadata and error attribution.
Sourcepub fn with_default_fields(self, default_fields: impl Into<String>) -> Self
pub fn with_default_fields(self, default_fields: impl Into<String>) -> Self
Sets the default field projection used when --fields is absent.
Sourcepub fn with_auth_provider(self, provider: impl Into<String>) -> Self
pub fn with_auth_provider(self, provider: impl Into<String>) -> Self
Selects the auth provider for this command.
Sourcepub fn no_auth(self, no_auth: bool) -> Self
pub fn no_auth(self, no_auth: bool) -> Self
Marks the command as no-auth.
no_auth(true) sets AuthRequirement::None: the command never resolves
a credential and default-env injection is suppressed. no_auth(false)
restores the default AuthRequirement::Required.
Sourcepub fn auth(self, requirement: AuthRequirement) -> Self
pub fn auth(self, requirement: AuthRequirement) -> Self
Sets the command’s AuthRequirement explicitly.
Sourcepub fn auth_optional(self) -> Self
pub fn auth_optional(self) -> Self
Marks authentication as optional (AuthRequirement::Optional).
The engine does not resolve a credential before the handler runs; the
handler triggers the auth flow only by calling
CredentialResolver::resolve/try_resolve.
Use for commands that should still run when the user is logged out.
Sourcepub fn with_auth_metadata(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_auth_metadata( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Adds provider-specific auth metadata.
Sourcepub fn with_scopes(self, scopes: &[impl AsRef<str>]) -> Self
pub fn with_scopes(self, scopes: &[impl AsRef<str>]) -> Self
Declares the OAuth scopes this command requires.
Sugar over with_auth_metadata with the
"scopes" key (whitespace-joined). The scopes surface on
CommandMeta::scopes and reach the auth provider via
CredentialRequest; a provider that supports
scope step-up re-authenticates when the cached token lacks them.
Sourcepub fn with_output_schema<T: OutputSchema>(self) -> Self
pub fn with_output_schema<T: OutputSchema>(self) -> Self
Registers a compact framework schema from an OutputSchema type.
Sourcepub fn with_json_schema<T: JsonSchema>(self) -> Self
pub fn with_json_schema<T: JsonSchema>(self) -> Self
Registers JSON Schema generated from a Rust type with schemars.
Sourcepub fn mutates(self, mutates: bool) -> Self
pub fn mutates(self, mutates: bool) -> Self
Marks whether the command should short-circuit under --dry-run.
Sourcepub fn metadata(&self) -> CommandMeta
pub fn metadata(&self) -> CommandMeta
Builds middleware metadata from the spec.
Sourcepub fn clap_command(&self) -> Command
pub fn clap_command(&self) -> Command
Builds the clap command for parser registration.
Trait Implementations§
Source§impl Clone for CommandSpec
impl Clone for CommandSpec
Source§fn clone(&self) -> CommandSpec
fn clone(&self) -> CommandSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more