pub struct CliBuilder { /* private fields */ }Expand description
Main builder for creating composable CLI applications
§Examples
use clap_noun_verb::{CliBuilder, noun, verb, VerbArgs, Result};
fn main() -> Result<()> {
let cli = CliBuilder::new()
.name("myapp")
.about("My application")
.noun(noun!("services", "Manage services", [
verb!("status", "Show status", |_args: &VerbArgs| {
println!("Services are running");
Ok(())
}),
]));
cli.run()
}Implementations§
Source§impl CliBuilder
impl CliBuilder
Sourcepub fn new() -> CliBuilder
pub fn new() -> CliBuilder
Create a new CLI builder
Sourcepub fn name(self, name: impl Into<String>) -> CliBuilder
pub fn name(self, name: impl Into<String>) -> CliBuilder
Set the application name
Sourcepub fn about(self, about: impl Into<String>) -> CliBuilder
pub fn about(self, about: impl Into<String>) -> CliBuilder
Set the application description
Sourcepub fn version(self, version: impl Into<String>) -> CliBuilder
pub fn version(self, version: impl Into<String>) -> CliBuilder
Set the application version
Sourcepub fn global_args(self, args: Vec<Arg>) -> CliBuilder
pub fn global_args(self, args: Vec<Arg>) -> CliBuilder
Add global arguments available to all commands
Sourcepub fn auto_validate(self, enable: bool) -> CliBuilder
pub fn auto_validate(self, enable: bool) -> CliBuilder
Enable automatic validation of command structure
Sourcepub fn noun(self, noun: impl NounCommand + 'static) -> CliBuilder
pub fn noun(self, noun: impl NounCommand + 'static) -> CliBuilder
Add a noun command to the CLI
Sourcepub fn nouns<I>(self, nouns: I) -> CliBuilder
pub fn nouns<I>(self, nouns: I) -> CliBuilder
Add multiple noun commands
Sourcepub fn run(self) -> Result<(), NounVerbError>
pub fn run(self) -> Result<(), NounVerbError>
Run the CLI application
Sourcepub fn run_with_args(self, args: Vec<String>) -> Result<(), NounVerbError>
pub fn run_with_args(self, args: Vec<String>) -> Result<(), NounVerbError>
Run the CLI application with custom args
Sourcepub fn build_command(self) -> Command
pub fn build_command(self) -> Command
Get the built command for testing or manual execution
Sourcepub fn registry(self) -> CommandRegistry
pub fn registry(self) -> CommandRegistry
Get the underlying registry for advanced usage
Sourcepub fn registry_ref(&self) -> &CommandRegistry
pub fn registry_ref(&self) -> &CommandRegistry
Get a reference to the registry for introspection
Sourcepub fn command_structure(&self) -> HashMap<String, Vec<String>>
pub fn command_structure(&self) -> HashMap<String, Vec<String>>
Get the command structure for introspection
Sourcepub fn has_command(&self, name: &str) -> bool
pub fn has_command(&self, name: &str) -> bool
Check if a command exists
Trait Implementations§
Source§impl Default for CliBuilder
impl Default for CliBuilder
Source§fn default() -> CliBuilder
fn default() -> CliBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CliBuilder
impl !RefUnwindSafe for CliBuilder
impl Send for CliBuilder
impl Sync for CliBuilder
impl Unpin for CliBuilder
impl !UnwindSafe for CliBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request