Merge branch 'main' into 'main'
Change argument parsing to clap v3 derives See merge request crystal/programs/amethyst!18i18n
commit
51aee8e721
@ -0,0 +1,85 @@
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
#[clap(name="Amethyst", version=env!("CARGO_PKG_VERSION"), about=env!("CARGO_PKG_DESCRIPTION"))]
|
||||
pub struct Args {
|
||||
#[clap(subcommand)]
|
||||
pub subcommand: Option<Operation>,
|
||||
|
||||
/// Sets the level of verbosity
|
||||
#[clap(long, short, parse(from_occurrences))]
|
||||
pub verbose: usize,
|
||||
|
||||
/// Complete operation without prompting user
|
||||
#[clap(long = "noconfirm")]
|
||||
pub no_confirm: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Subcommand)]
|
||||
pub enum Operation {
|
||||
/// Installs a package from either the AUR or the PacMan-defined repositories
|
||||
#[clap(name="install", aliases=&["i", "-S"])]
|
||||
Install(InstallArgs),
|
||||
|
||||
/// Removes a previously installed package
|
||||
#[clap(name="remove", aliases=&["rm", "-R", "-Rs"])]
|
||||
Remove(RemoveArgs),
|
||||
|
||||
/// Searches for the relevant packages in both the AUR and repos
|
||||
#[clap(name="search", aliases=&["sea", "-Ss"])]
|
||||
Search(SearchArgs),
|
||||
|
||||
/// Queries installed packages
|
||||
#[clap(name="query", aliases=&["ls", "-Q"])]
|
||||
Query(QueryArgs),
|
||||
|
||||
/// Upgrades locally installed packages to their latest versions
|
||||
#[clap(name="upgrade", aliases=&["upg", "-Syu"])]
|
||||
Upgrade,
|
||||
}
|
||||
|
||||
impl Default for Operation {
|
||||
fn default() -> Self {
|
||||
Self::Upgrade
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Parser)]
|
||||
pub struct InstallArgs {
|
||||
/// The name of the package(s) to install
|
||||
#[clap(required = true)]
|
||||
pub packages: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Parser)]
|
||||
pub struct RemoveArgs {
|
||||
/// The name of the package(s) to remove
|
||||
#[clap(required = true)]
|
||||
pub packages: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Parser)]
|
||||
pub struct SearchArgs {
|
||||
/// Searches for the relevant packages in both the AUR and repos
|
||||
#[clap(long, short)]
|
||||
pub aur: bool,
|
||||
|
||||
/// Searches only local repos for the package
|
||||
#[clap(long, short)]
|
||||
pub repo: bool,
|
||||
|
||||
/// The string the package must match in the search
|
||||
#[clap(required = true)]
|
||||
pub search: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Parser)]
|
||||
pub struct QueryArgs {
|
||||
/// Lists AUR/foreign packages
|
||||
#[clap(long, short)]
|
||||
pub aur: bool,
|
||||
|
||||
/// Lists repo/native packages
|
||||
#[clap(long, short)]
|
||||
pub repo: bool,
|
||||
}
|
@ -1,23 +1,9 @@
|
||||
use crate::internal::rpc::Package;
|
||||
use crate::Options;
|
||||
|
||||
mod add;
|
||||
mod initialise;
|
||||
mod query;
|
||||
mod remove;
|
||||
|
||||
pub fn add(a: Package, options: Options) {
|
||||
add::add(a, options);
|
||||
}
|
||||
|
||||
pub fn remove(a: &str, options: Options) {
|
||||
remove::remove(a, options);
|
||||
}
|
||||
|
||||
pub fn init(options: Options) {
|
||||
initialise::init(options);
|
||||
}
|
||||
|
||||
pub fn query(options: Options) -> Vec<Package> {
|
||||
query::query(options)
|
||||
}
|
||||
pub use add::*;
|
||||
pub use initialise::*;
|
||||
pub use query::*;
|
||||
pub use remove::*;
|
||||
|
@ -1,31 +1,11 @@
|
||||
use crate::Options;
|
||||
|
||||
mod aur_install;
|
||||
mod install;
|
||||
mod search;
|
||||
mod uninstall;
|
||||
mod upgrade;
|
||||
|
||||
pub fn install(a: Vec<String>, options: Options) {
|
||||
install::install(a, options);
|
||||
}
|
||||
|
||||
pub fn uninstall(a: Vec<String>, options: Options) {
|
||||
uninstall::uninstall(a, options);
|
||||
}
|
||||
|
||||
pub fn search(a: &str, options: Options) {
|
||||
search::repo_search(a, options);
|
||||
}
|
||||
|
||||
pub fn aur_install(a: Vec<String>, options: Options) {
|
||||
aur_install::aur_install(a, options);
|
||||
}
|
||||
|
||||
pub fn aur_search(a: &str, options: Options) {
|
||||
search::aur_search(a, options);
|
||||
}
|
||||
|
||||
pub fn upgrade(options: Options) {
|
||||
upgrade::upgrade(options);
|
||||
}
|
||||
pub use aur_install::*;
|
||||
pub use install::*;
|
||||
pub use search::{aur_search, repo_search as search};
|
||||
pub use uninstall::*;
|
||||
pub use upgrade::*;
|
||||
|
Loading…
Reference in New Issue