help: move to clap 4 and localize strings

i18n
Fries 2 years ago committed by fries1234
parent 60db2c444d
commit b3710431f8

84
Cargo.lock generated

@ -267,36 +267,34 @@ checksum = "8628d1f5b9a7b1196ce1aa660e3ba7e2559d350649cbe94993519c127df667f2"
[[package]] [[package]]
name = "clap" name = "clap"
version = "3.2.20" version = "4.0.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b71c3ce99b7611011217b366d923f1d0a7e07a92bb2dbf1e84508c673ca3bd" checksum = "9b01032b244c348ae40c5d99113438c95ee7343cd303bb361fc06dcb4c1d93e8"
dependencies = [ dependencies = [
"atty", "atty",
"bitflags", "bitflags",
"clap_derive", "clap_derive",
"clap_lex", "clap_lex",
"indexmap",
"once_cell", "once_cell",
"strsim", "strsim",
"termcolor", "termcolor",
"terminal_size", "terminal_size 0.2.1",
"textwrap 0.15.0",
] ]
[[package]] [[package]]
name = "clap_complete" name = "clap_complete"
version = "3.2.4" version = "4.0.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4179da71abd56c26b54dd0c248cc081c1f43b0a1a7e8448e28e57a29baa993d" checksum = "f00c7ed9ef8826baf070d8f477714b0d9219f8d15744d1b5267cc8a89a1f0286"
dependencies = [ dependencies = [
"clap", "clap",
] ]
[[package]] [[package]]
name = "clap_complete_fig" name = "clap_complete_fig"
version = "3.2.4" version = "4.0.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed37b4c0c1214673eba6ad8ea31666626bf72be98ffb323067d973c48b4964b9" checksum = "f4b69e49c3d0f340f0e83db62e1d79953418bf3b2af0a8e71f131a5b72ebe246"
dependencies = [ dependencies = [
"clap", "clap",
"clap_complete", "clap_complete",
@ -304,9 +302,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "3.2.18" version = "4.0.0-rc.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" checksum = "51eef4d62724bf369e9ca7458cfde0c55263708b4552020058fba384864e8c23"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro-error", "proc-macro-error",
@ -317,9 +315,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_lex" name = "clap_lex"
version = "0.2.4" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
dependencies = [ dependencies = [
"os_str_bytes", "os_str_bytes",
] ]
@ -391,7 +389,7 @@ dependencies = [
"encode_unicode", "encode_unicode",
"libc", "libc",
"once_cell", "once_cell",
"terminal_size", "terminal_size 0.1.17",
"unicode-width", "unicode-width",
"winapi", "winapi",
] ]
@ -568,6 +566,27 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "errno"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
dependencies = [
"errno-dragonfly",
"libc",
"winapi",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]] [[package]]
name = "eyre" name = "eyre"
version = "0.6.8" version = "0.6.8"
@ -1067,6 +1086,12 @@ dependencies = [
"unic-langid", "unic-langid",
] ]
[[package]]
name = "io-lifetimes"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ea37f355c05dde75b84bba2d767906ad522e97cd9e2eef2be7a4ab7fb442c06"
[[package]] [[package]]
name = "ipnet" name = "ipnet"
version = "2.5.0" version = "2.5.0"
@ -1140,6 +1165,12 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
[[package]]
name = "linux-raw-sys"
version = "0.0.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d"
[[package]] [[package]]
name = "locale_config" name = "locale_config"
version = "0.3.0" version = "0.3.0"
@ -1800,6 +1831,20 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustix"
version = "0.35.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72c825b8aa8010eb9ee99b75f05e10180b9278d161583034d7574c9d617aeada"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.11" version = "1.0.11"
@ -2046,6 +2091,16 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "terminal_size"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8440c860cf79def6164e4a0a983bcc2305d82419177a0e0c71930d049e3ac5a1"
dependencies = [
"rustix",
"windows-sys",
]
[[package]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.13.4" version = "0.13.4"
@ -2062,7 +2117,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
dependencies = [ dependencies = [
"smawk", "smawk",
"terminal_size",
"unicode-linebreak", "unicode-linebreak",
"unicode-width", "unicode-width",
] ]

@ -30,7 +30,7 @@ alpm-utils = "2.0.0"
pacmanconf = "2.0.0" pacmanconf = "2.0.0"
chrono = { version = "0.4.22", default-features = false, features = [ "clock", "std", "wasmbind" ] } chrono = { version = "0.4.22", default-features = false, features = [ "clock", "std", "wasmbind" ] }
trigram = "0.4.4" trigram = "0.4.4"
clap = { version = "3.2.17", features = [ "derive", "wrap_help" ] } clap = { version = "4.0.0-rc.1", features = [ "derive", "wrap_help" ] }
regex = { version = "1.6.0", default-features = false, features = [ "std", "unicode-perl" ] } regex = { version = "1.6.0", default-features = false, features = [ "std", "unicode-perl" ] }
colored = "2.0.0" colored = "2.0.0"
serde = { version = "1.0.144", default-features = false, features = [ "derive", "serde_derive" ] } serde = { version = "1.0.144", default-features = false, features = [ "derive", "serde_derive" ] }
@ -44,8 +44,8 @@ tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
textwrap = "0.15.0" textwrap = "0.15.0"
crossterm = "0.25.0" crossterm = "0.25.0"
toml = "0.5.9" toml = "0.5.9"
clap_complete = "3.2.4" clap_complete = "4.0.0-rc.1"
clap_complete_fig = "3.2.4" clap_complete_fig = "4.0.0-rc.1"
color-eyre = { version = "0.6.2", features = ["issue-url", "url"] } color-eyre = { version = "0.6.2", features = ["issue-url", "url"] }
indicatif = { version = "0.17.0", features = ["tokio"] } indicatif = { version = "0.17.0", features = ["tokio"] }
lazy_static = "1.4.0" lazy_static = "1.4.0"

@ -149,3 +149,30 @@ quit = quit
search = search search = search
next-result = next result next-result = next result
previous-result = previous result previous-result = previous result
# --help
verbose = Sets the level of verbosity
no-confirm = Complete operation without prompting user
quiet = Make some commands have less output (only clean, upgrade, and install are supported)
sudoloop = Loops sudo in the background to ensure it doesn't time out during long builds
cachedir = Sets a custom AUR clone and build directory for the specified operation
install = Installs or searches for a package in either the AUR or the Pacman-defined repositories
remove = Removes a previously installed package
search = Searches for packages matching a provided pattern in the AUR/repos [aliases: -Ss]
query = Queries installed packages
upgrade = Upgrades locally installed packages to their latest versions (Default)
gencomp = Generates shell completions for supported shells (bash, fish, elvish, pwsh)
clean = Removes all orphaned packages
diff = Runs pacdiff
install-packages = The name of the package(s) to install or search for
install-aur = Operate only on AUR packages
install-repo = Operate only on repo packages
install-search = Search packages for a given pattern instead of installing
install-by = Searches by a specific field
remove-packages = The name of the package(s) to remove
query-aur = Lists AUR/foreign packages [-Qa, -Qm]
query-repo = Lists repo/native packages [-Qr, -Qn]
query-info = Get information about a specific package
upgrade-repo = Upgrades only repo/native packages
upgrade-aur = Upgrades only from the AUR
gencomp-shell = The shell to generate completions for (bash, fish, elvish, pwsh, fig)

@ -1,7 +1,7 @@
#![allow(clippy::module_name_repetitions)] #![allow(clippy::module_name_repetitions)]
use crate::operations::SearchBy; use crate::{fl, operations::SearchBy};
use clap::{Parser, Subcommand, ValueHint}; use clap::{ArgAction, Parser, Subcommand, ValueHint};
static VERSION: &str = concat!( static VERSION: &str = concat!(
env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_VERSION"),
@ -13,67 +13,54 @@ static VERSION: &str = concat!(
#[derive(Debug, Clone, Parser)] #[derive(Debug, Clone, Parser)]
#[clap(bin_name = "ame", name = "Amethyst", version = VERSION, about = env ! ("CARGO_PKG_DESCRIPTION"), infer_subcommands = true)] #[clap(bin_name = "ame", name = "Amethyst", version = VERSION, about = env ! ("CARGO_PKG_DESCRIPTION"), infer_subcommands = true)]
pub struct Args { pub struct Args {
#[clap(subcommand)] #[command(subcommand)]
pub subcommand: Option<Operation>, pub subcommand: Option<Operation>,
/// Sets the level of verbosity #[arg(long, short, action = ArgAction::Count, global = true, help = fl!("verbose"))]
#[clap(long, short, parse(from_occurrences), global = true)] pub verbose: u8,
pub verbose: usize,
/// Complete operation without prompting user #[arg(long = "noconfirm", global = true, help = fl!("no-confirm"))]
#[clap(long = "noconfirm", global = true)]
pub no_confirm: bool, pub no_confirm: bool,
/// Make some commands have less output (only clean, upgrade, and install are supported)
#[clap(long, short, global = true)]
// not gonna lie the only reason this option is here is because // not gonna lie the only reason this option is here is because
// i was trying to figure out if paccache had a --noconfirm option. // i was trying to figure out if paccache had a --noconfirm option.
// so basically, it doesn't, but hey, we might as well have it here // so basically, it doesn't, but hey, we might as well have it here
// anyways as some pacman commands can have a --quiet flag passed // anyways as some pacman commands can have a --quiet flag passed
// to them. // to them.
#[arg(long, short, global = true, help = fl!("quiet"))]
pub quiet: bool, pub quiet: bool,
/// Loops sudo in the background to ensure it doesn't time out during long builds #[arg(long = "sudoloop", global = true, help = fl!("sudoloop"))]
#[clap(long = "sudoloop", global = true)]
pub sudoloop: bool, pub sudoloop: bool,
/// Sets a custom AUR clone and build directory for the specified operation #[arg(long, short, global = true, value_hint = ValueHint::DirPath, help = fl!("cachedir"))]
#[clap(long, short, global = true, value_hint = ValueHint::DirPath)]
pub cachedir: Option<String>, pub cachedir: Option<String>,
} }
#[derive(Debug, Clone, Subcommand)] #[derive(Debug, Clone, Subcommand)]
pub enum Operation { pub enum Operation {
/// Installs or searches for a package in either the AUR or the Pacman-defined repositories #[command(bin_name = "ame", name = "sync", aliases = & [ "-S" ], visible_aliases = & ["install", "i"], short_flag = 'S', about = fl!("install"))]
#[clap(bin_name = "ame", name = "sync", aliases = & [ "-S" ], visible_aliases = & ["install", "i"], short_flag = 'S')]
Install(InstallArgs), Install(InstallArgs),
/// Removes a previously installed package #[command(bin_name = "ame", name = "remove", visible_aliases = & ["rm"], short_flag = 'R', about = fl!("remove"))]
#[clap(bin_name = "ame", name = "remove", visible_aliases = & ["rm"], short_flag = 'R')]
Remove(RemoveArgs), Remove(RemoveArgs),
/// Searches for packages matching a provided pattern in the AUR/repos [aliases: -Ss] #[command(bin_name = "ame", name = "search", about = fl!("search"))]
#[clap(bin_name = "ame", name = "search")]
Search(InstallArgs), Search(InstallArgs),
/// Queries installed packages #[command(bin_name = "ame", name = "query", short_flag = 'Q', about = fl!("query"))]
#[clap(bin_name = "ame", name = "query", short_flag = 'Q')]
Query(QueryArgs), Query(QueryArgs),
/// Upgrades locally installed packages to their latest versions (Default) #[command(bin_name = "ame", name = "upgrade", visible_aliases = & ["-Syu"], about = fl!("upgrade"))]
#[clap(bin_name = "ame", name = "upgrade", visible_aliases = & ["-Syu"])]
Upgrade(UpgradeArgs), Upgrade(UpgradeArgs),
/// Generates shell completions for supported shells (bash, fish, elvish, pwsh) #[command(bin_name = "ame", name = "gencomp", short_flag = 'G', about = fl!("gencomp"))]
#[clap(bin_name = "ame", name = "gencomp", short_flag = 'G')]
GenComp(GenCompArgs), GenComp(GenCompArgs),
/// Removes all orphaned packages #[command(bin_name = "ame", name = "clean", short_flag = 'C', about = fl!("clean"))]
#[clap(bin_name = "ame", name = "clean", short_flag = 'C')]
Clean, Clean,
/// Runs pacdiff #[command(bin_name = "ame", name = "diff", short_flag = 'd', about = fl!("diff"))]
#[clap(bin_name = "ame", name = "diff", short_flag = 'd')]
Diff, Diff,
} }
@ -85,63 +72,51 @@ impl Default for Operation {
#[derive(Default, Debug, Clone, Parser)] #[derive(Default, Debug, Clone, Parser)]
pub struct InstallArgs { pub struct InstallArgs {
/// The name of the package(s) to install or search for #[arg(required = true, help = fl!("install-packages"))]
#[clap(required = true)]
pub packages: Vec<String>, pub packages: Vec<String>,
/// Operate only on AUR packages #[arg(long, short, help = fl!("install-aur"))]
#[clap(long, short)]
pub aur: bool, pub aur: bool,
/// Operate only on repo packages #[arg(long, short, help = fl!("install-repo"))]
#[clap(long, short)]
pub repo: bool, pub repo: bool,
/// Search packages for a given pattern instead of installing #[arg(hide = true, short = 's', help = fl!("install-search"))]
#[clap(hidden = true, short = 's')]
pub search: bool, pub search: bool,
/// Searches by a specific field #[arg(long, short, help = fl!("install-by"))]
#[clap(long, short)]
pub by: Option<SearchBy>, pub by: Option<SearchBy>,
} }
#[derive(Default, Debug, Clone, Parser)] #[derive(Default, Debug, Clone, Parser)]
pub struct RemoveArgs { pub struct RemoveArgs {
/// The name of the package(s) to remove #[arg(required = true, help = fl!("remove-packages"))]
#[clap(required = true)]
pub packages: Vec<String>, pub packages: Vec<String>,
} }
#[derive(Default, Debug, Clone, Parser)] #[derive(Default, Debug, Clone, Parser)]
pub struct QueryArgs { pub struct QueryArgs {
/// Lists AUR/foreign packages [-Qa, -Qm] #[arg(long, short, help = fl!("query-aur"))]
#[clap(long, short)]
pub aur: bool, pub aur: bool,
/// Lists repo/native packages [-Qr, -Qn] #[arg(long, short, help = fl!("query-repo"))]
#[clap(long, short)]
pub repo: bool, pub repo: bool,
/// Get information about a specific package #[arg(long, short, help = fl!("query-info"))]
#[clap(long, short)]
pub info: Option<String>, pub info: Option<String>,
} }
#[derive(Default, Debug, Clone, Parser)] #[derive(Default, Debug, Clone, Parser)]
pub struct UpgradeArgs { pub struct UpgradeArgs {
/// Upgrades only repo/native packages #[arg(long, short, help = fl!("upgrade-repo"))]
#[clap(long, short)]
pub repo: bool, pub repo: bool,
/// Upgrades only from the AUR #[arg(long, short, help = fl!("upgrade-aur"))]
#[clap(long, short)]
pub aur: bool, pub aur: bool,
} }
#[derive(Default, Debug, Clone, Parser)] #[derive(Default, Debug, Clone, Parser)]
pub struct GenCompArgs { pub struct GenCompArgs {
/// The shell to generate completions for (bash, fish, elvish, pwsh, fig) #[arg(required = true, help = fl!("gencomp-shell"))]
#[clap(required = true)]
pub shell: String, pub shell: String,
} }

@ -35,7 +35,7 @@ async fn main() {
} }
let args: Args = Args::parse(); let args: Args = Args::parse();
init_logger(args.verbose.into()); init_logger(usize::from(args.verbose).into());
let noconfirm = args.no_confirm; let noconfirm = args.no_confirm;
let quiet = args.quiet; let quiet = args.quiet;

Loading…
Cancel
Save