pub struct Cli { /* private fields */ }Expand description
Main CLI structure for AGPM (Claude Code Package Manager).
This struct represents the root command and all its global options. It uses the
clap derive API to automatically generate command-line parsing, help text, and
validation. All options marked as global = true are available to all subcommands.
§Design Philosophy
The CLI follows standard Unix conventions:
- Short options use single dashes (
-v) - Long options use double dashes (
--verbose) - Global options work with all subcommands
- Mutually exclusive options are validated automatically
§Global Options
All subcommands inherit these global options:
- Verbosity control:
--verboseand--quietfor output level - Configuration:
--configfor custom config file paths - UI control:
--no-progressfor automation-friendly output
§Examples
# Basic command with global options
agpm --verbose install
agpm --quiet --no-progress list
agpm --config ./custom.toml validate
# Global options work with any subcommand
agpm --verbose install
agpm --quiet cache clean§Subcommand Structure
Commands are organized by functionality:
- Project management:
install,update,add,remove - Information:
list,validate - System:
cache,config,upgrade
§Integration Points
This CLI integrates with:
CliConfigfor dependency injection and testing- Environment variables for runtime configuration
- Global and project-specific configuration files
- Cross-platform file system operations
§Main CLI application structure for AGPM
This struct represents the top-level command-line interface for the Claude Code Package Manager. It handles global flags and delegates to subcommands for specific operations.
Implementations§
Source§impl Cli
impl Cli
Sourcepub async fn execute(self) -> Result<()>
pub async fn execute(self) -> Result<()>
Execute the CLI with default configuration.
This is the main entry point for CLI execution. It builds a configuration
from the parsed command-line arguments and delegates to execute_with_config.
§Process Flow
- Configuration Building: Converts CLI arguments to
CliConfig - Environment Setup: Applies configuration to process environment
- Command Dispatch: Routes to the appropriate subcommand handler
- Error Handling: Provides user-friendly error messages
§Returns
Ok(())if the command executed successfullyErr(anyhow::Error)if the command failed with details for user feedback
§Examples
use agpm_cli::cli::Cli;
use clap::Parser;
let cli = Cli::parse(); // From command-line arguments
cli.execute().await?;Sourcepub fn build_config(&self) -> CliConfig
pub fn build_config(&self) -> CliConfig
Build a CliConfig from the parsed CLI arguments.
This method translates command-line flags into a structured configuration that can be applied to the environment or injected into tests.
§Configuration Logic
- Verbose mode: Sets log level to “debug” for detailed output
- Quiet mode: Disables logging for automation-friendly output
- Default mode: Uses “info” level for normal operation
- Progress control: Honors
--no-progressflag for animations - Config path: Uses custom config file if specified
§Validation
The CLI parser already handles mutual exclusion between --verbose and
--quiet, so this method doesn’t need additional validation.
§Returns
A CliConfig instance ready for environment application or testing.
§Examples
use agpm_cli::cli::Cli;
use clap::Parser;
let cli = Cli::parse_from(&["agpm", "--verbose", "install"]);
let config = cli.build_config();
assert_eq!(config.log_level, Some("debug".to_string()));Sourcepub async fn execute_with_config(self, config: CliConfig) -> Result<()>
pub async fn execute_with_config(self, config: CliConfig) -> Result<()>
Execute the CLI with a specific configuration for dependency injection.
This method enables testing and programmatic usage by accepting an external configuration instead of building one from CLI arguments. It’s the core execution method that all entry points eventually call.
§Design Benefits
- Testability: Tests can inject custom configurations
- Flexibility: Programmatic usage without CLI parsing
- No Global State: Configuration passed explicitly, no environment variables
- Consistency: Single execution path for all scenarios
§Arguments
config- The configuration to pass to command execution
§Execution Flow
- Command Matching: Dispatches to the appropriate subcommand
- Config Passing: Passes configuration to commands that need it
- Async Execution: Awaits the async command execution
- Error Propagation: Returns any errors for higher-level handling
§Returns
Ok(())if the command completed successfullyErr(anyhow::Error)if the command failed with context for debugging
§Examples
use agpm_cli::cli::{Cli, CliConfig};
use clap::Parser;
let cli = Cli::parse_from(&["agpm", "install"]);
let mut config = CliConfig::new();
config.log_level = Some("trace".to_string());
config.no_progress = true;
cli.execute_with_config(config).await?;Trait Implementations§
Source§impl Args for Cli
impl Args for Cli
Source§fn augment_args<'b>(__clap_app: Command) -> Command
fn augment_args<'b>(__clap_app: Command) -> Command
Source§fn augment_args_for_update<'b>(__clap_app: Command) -> Command
fn augment_args_for_update<'b>(__clap_app: Command) -> Command
Command so it can instantiate self via
FromArgMatches::update_from_arg_matches_mut Read moreSource§impl CommandFactory for Cli
impl CommandFactory for Cli
Source§impl FromArgMatches for Cli
impl FromArgMatches for Cli
Source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
Source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches,
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>
Source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§impl Parser for Cli
impl Parser for Cli
Source§fn parse_from<I, T>(itr: I) -> Self
fn parse_from<I, T>(itr: I) -> Self
Source§fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
Source§fn update_from<I, T>(&mut self, itr: I)
fn update_from<I, T>(&mut self, itr: I)
Auto Trait Implementations§
impl Freeze for Cli
impl RefUnwindSafe for Cli
impl Send for Cli
impl Sync for Cli
impl Unpin for Cli
impl UnwindSafe for Cli
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
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>
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>
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 more