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

@ -30,7 +30,7 @@ alpm-utils = "2.0.0"
pacmanconf = "2.0.0"
chrono = { version = "0.4.22", default-features = false, features = [ "clock", "std", "wasmbind" ] }
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" ] }
colored = "2.0.0"
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"
crossterm = "0.25.0"
toml = "0.5.9"
clap_complete = "3.2.4"
clap_complete_fig = "3.2.4"
clap_complete = "4.0.0-rc.1"
clap_complete_fig = "4.0.0-rc.1"
color-eyre = { version = "0.6.2", features = ["issue-url", "url"] }
indicatif = { version = "0.17.0", features = ["tokio"] }
lazy_static = "1.4.0"

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

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

Loading…
Cancel
Save