Cli

Struct Cli 

Source
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: --verbose and --quiet for output level
  • Configuration: --config for custom config file paths
  • UI control: --no-progress for 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:

  • CliConfig for 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

Source

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
  1. Configuration Building: Converts CLI arguments to CliConfig
  2. Environment Setup: Applies configuration to process environment
  3. Command Dispatch: Routes to the appropriate subcommand handler
  4. Error Handling: Provides user-friendly error messages
§Returns
  • Ok(()) if the command executed successfully
  • Err(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?;
Source

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-progress flag 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()));
Source

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
  1. Command Matching: Dispatches to the appropriate subcommand
  2. Config Passing: Passes configuration to commands that need it
  3. Async Execution: Awaits the async command execution
  4. Error Propagation: Returns any errors for higher-level handling
§Returns
  • Ok(()) if the command completed successfully
  • Err(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

Source§

fn group_id() -> Option<Id>

Report the ArgGroup::id for this set of arguments
Source§

fn augment_args<'b>(__clap_app: Command) -> Command

Append to Command so it can instantiate Self via FromArgMatches::from_arg_matches_mut Read more
Source§

fn augment_args_for_update<'b>(__clap_app: Command) -> Command

Append to Command so it can instantiate self via FromArgMatches::update_from_arg_matches_mut Read more
Source§

impl CommandFactory for Cli

Source§

fn command<'b>() -> Command

Build a Command that can instantiate Self. Read more
Source§

fn command_for_update<'b>() -> Command

Build a Command that can update self. Read more
Source§

impl FromArgMatches for Cli

Source§

fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
Source§

fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
Source§

fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>

Assign values from ArgMatches to self.
Source§

fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>

Assign values from ArgMatches to self.
Source§

impl Parser for Cli

Source§

fn parse() -> Self

Parse from std::env::args_os(), exit on error.
Source§

fn try_parse() -> Result<Self, Error>

Parse from std::env::args_os(), return Err on error.
Source§

fn parse_from<I, T>(itr: I) -> Self
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, exit on error.
Source§

fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, return Err on error.
Source§

fn update_from<I, T>(&mut self, itr: I)
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, exit on error. Read more
Source§

fn try_update_from<I, T>(&mut self, itr: I) -> Result<(), Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, return Err on error.

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> 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> 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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