diff --git a/Cargo.lock b/Cargo.lock index 0098356..cd93ecb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,54 @@ dependencies = [ "memchr", ] +[[package]] +name = "anstream" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" +dependencies = [ + "anstyle", + "windows-sys", +] + [[package]] name = "anyhow" version = "1.0.75" @@ -23,17 +71,6 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -89,7 +126,7 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cargo-i18n" -version = "0.2.11" +version = "0.2.12" dependencies = [ "anyhow", "clap", @@ -123,28 +160,36 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.2.25" +version = "4.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +checksum = "824956d0dca8334758a5b7f7e50518d66ea319330cbceedcf76905c2f6ab30e3" dependencies = [ - "atty", - "bitflags 1.3.2", + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122ec64120a49b4563ccaedcbea7818d069ed8e9aa6d829b82d8a4128936b2ab" +dependencies = [ + "anstream", + "anstyle", "clap_lex", - "indexmap 1.9.3", - "once_cell", "strsim", - "termcolor", - "textwrap", ] [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "cpufeatures" @@ -172,7 +217,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if", - "hashbrown 0.14.0", + "hashbrown", "lock_api", "once_cell", "parking_lot_core", @@ -485,27 +530,12 @@ dependencies = [ "temp-dir", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hashbrown" version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.2" @@ -537,19 +567,19 @@ dependencies = [ [[package]] name = "i18n-config" -version = "0.4.5" +version = "0.4.6" dependencies = [ "log", "serde", "serde_derive", "thiserror", - "toml 0.7.8", + "toml 0.8.1", "unic-langid", ] [[package]] name = "i18n-embed" -version = "0.14.0" +version = "0.14.1" dependencies = [ "arc-swap", "doc-comment", @@ -610,16 +640,6 @@ dependencies = [ "syn 2.0.31", ] -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] - [[package]] name = "indexmap" version = "2.0.0" @@ -627,7 +647,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" dependencies = [ "equivalent", - "hashbrown 0.14.0", + "hashbrown", ] [[package]] @@ -655,7 +675,7 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi", "rustix", "windows-sys", ] @@ -782,12 +802,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "os_str_bytes" -version = "6.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" - [[package]] name = "parking_lot" version = "0.12.1" @@ -1119,12 +1133,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "thiserror" version = "1.0.48" @@ -1165,9 +1173,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.7.8" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +checksum = "1bc1433177506450fe920e46a4f9812d0c211f5dd556da10e731a0a3dfa151f0" dependencies = [ "serde", "serde_spanned", @@ -1186,11 +1194,11 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.19.15" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +checksum = "ca676d9ba1a322c1b64eb8045a5ec5c0cfb0c9d08e15e9ff622589ad5221c8fe" dependencies = [ - "indexmap 2.0.0", + "indexmap", "serde", "serde_spanned", "toml_datetime", @@ -1248,6 +1256,12 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 0ecd418..f6ac69a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" name = "cargo-i18n" readme = "README.md" repository = "https://github.com/kellpossible/cargo-i18n" -version = "0.2.11" +version = "0.2.12" [badges] maintenance = { status = "actively-developed" } @@ -22,7 +22,7 @@ i18n-config = { workspace = true } anyhow = { workspace = true } gettext = { workspace = true } tr = { workspace = true, default-features = false, features = ["gettext"] } -clap = { version = "3.2.25", features = ["cargo"] } +clap = { version = "4.4.5", features = ["cargo"] } rust-embed = { workspace = true } unic-langid = { workspace = true } env_logger = { workspace = true } diff --git a/src/main.rs b/src/main.rs index 35a399f..76cf2b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use clap::{crate_authors, crate_version, App, Arg}; +use clap::{builder::PossibleValuesParser, crate_authors, crate_version, Arg, Command}; use i18n_build::run; use i18n_config::Crate; use i18n_embed::{ @@ -9,7 +9,10 @@ use i18n_embed::{ }; use lazy_static::lazy_static; use rust_embed::RustEmbed; -use std::{path::Path, sync::Arc}; +use std::{ + path::{Path, PathBuf}, + sync::Arc, +}; use tr::tr; use unic_langid::LanguageIdentifier; @@ -83,43 +86,46 @@ fn main() -> Result<()> { language_requester.add_listener(Arc::downgrade(&i18n_build_localizer_rc)); language_requester.poll()?; - let fallback_locale = LANGUAGE_LOADER.fallback_language().to_string(); + let fallback_locale: &'static str = + String::leak(LANGUAGE_LOADER.fallback_language().to_string()); let available_languages = available_languages(&cargo_i18n_localizer_rc)?; - let available_languages_slice: Vec<&str> = - available_languages.iter().map(|l| l.as_str()).collect(); + let available_languages_slice: Vec<&'static str> = available_languages + .into_iter() + .map(|l| String::leak(l) as &str) + .collect(); - let matches = App::new("cargo-i18n") + let matches = Command::new("cargo-i18n") .bin_name("cargo") .term_width(80) .about( tr!( // The message displayed when running the binary outside of cargo using `cargo-18n`. - "This binary is designed to be executed as a cargo subcommand using \"cargo i18n\".").as_str() + "This binary is designed to be executed as a cargo subcommand using \"cargo i18n\".") ) .version(crate_version!()) .author(crate_authors!()) - .subcommand(App::new("i18n") - .about(short_about().as_str()) - .long_about(long_about().as_str()) + .subcommand(Command::new("i18n") + .about(short_about()) + .long_about(long_about()) .version(crate_version!()) .author(crate_authors!()) .arg(Arg::new("path") .help( // The help message for the `--path` command line argument. - tr!("Path to the crate you want to localize (if not the current directory). The crate needs to contain \"i18n.toml\" in its root.").as_str() + tr!("Path to the crate you want to localize (if not the current directory). The crate needs to contain \"i18n.toml\" in its root.") ) .long("path") - .takes_value(true) + .num_args(1) ) - .arg(Arg::new("config file name") + .arg(Arg::new("config-file-name") .help( tr!( // The help message for the `-c`, `--config-file-name` command line argument. - "The name of the i18n config file for this crate").as_str() + "The name of the i18n config file for this crate") ) .long("config-file-name") .short('c') - .takes_value(true) + .num_args(1) .default_value("i18n.toml") ) .arg(Arg::new("language") @@ -127,34 +133,34 @@ fn main() -> Result<()> { tr!( // The help message for the `-l`, `--language` command line argument. "Set the language to use for this application. Overrides the language selected automatically by your operating system." - ).as_str() + ) ) - .long("--language") + .long("language") .short('l') - .takes_value(true) - .default_value(&fallback_locale) - .possible_values(available_languages_slice) + .num_args(1) + .default_value(&*fallback_locale) + .value_parser(PossibleValuesParser::new(available_languages_slice)) ) ) .get_matches(); if let Some(i18n_matches) = matches.subcommand_matches("i18n") { - let config_file_name = i18n_matches - .value_of("config file name") + let config_file_name: &String = i18n_matches + .get_one("config-file-name") .expect("expected a default config file name to be present"); - let language = i18n_matches - .value_of("language") + let language: &String = i18n_matches + .get_one("language") .expect("expected a default language to be present"); - let li: LanguageIdentifier = language.parse()?; + language_requester.set_language_override(Some(li))?; language_requester.poll()?; let path = i18n_matches - .value_of("path") - .map(|path_str| Path::new(path_str).to_path_buf()) - .unwrap_or_else(|| Path::new(".").to_path_buf()); + .get_one::("path") + .map(ToOwned::to_owned) + .unwrap_or_else(|| PathBuf::from(".")); let config_file_path = Path::new(config_file_name).to_path_buf();