diff --git a/Cargo.lock b/Cargo.lock index 9d9a64e..fcf3f3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,54 @@ dependencies = [ "memchr", ] +[[package]] +name = "anstream" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anstyle-parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" +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 = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +dependencies = [ + "anstyle", + "windows-sys", +] + [[package]] name = "anyhow" version = "1.0.75" @@ -128,28 +176,36 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.2.25" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" dependencies = [ - "atty", - "bitflags 1.3.2", + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" +dependencies = [ + "anstream", + "anstyle", "clap_lex", - "indexmap", - "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 = "core-foundation" @@ -647,12 +703,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "os_str_bytes" -version = "6.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" - [[package]] name = "percent-encoding" version = "2.3.0" @@ -1043,12 +1093,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 = "tinyvec" version = "1.6.0" @@ -1184,6 +1228,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index f6cd888..a0e4d6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ include = ["/src"] [dependencies] anyhow = "1.0.37" -clap = { version = "3.1.18", optional = true, features = ["cargo"] } +clap = { version = "4.4.6", optional = true, features = ["cargo"] } env_logger = { version = "0.9.0", optional = true } flate2 = "1.0.19" log = "0.4.11" @@ -28,7 +28,8 @@ tar = { version = "0.4.30", default-features = false } tempfile = "3.1.0" [features] -default = ["clap", "env_logger", "reqwest/default-tls"] +bin = ["dep:clap", "dep:env_logger"] +default = ["bin", "reqwest/default-tls"] rustls = ["reqwest/rustls-tls"] [lib] diff --git a/src/main.rs b/src/main.rs index dbec43f..6221594 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use cargo_clone; -use clap::{Arg, Command}; +use clap::{Arg, ArgAction, Command}; use env_logger::{Builder, Target}; use std::{env, io::Write, process::exit}; @@ -31,6 +31,7 @@ fn main() { let matches = Command::new("cargo-clone") .version(clap::crate_version!()) + .disable_version_flag(true) .bin_name("cargo") .subcommand_required(true) .propagate_version(true) @@ -41,8 +42,8 @@ fn main() { .arg( Arg::new("method") .long("method") - .takes_value(true) - .possible_values(&["crate", "git", "hg", "pijul", "fossil", "auto"]) + .action(ArgAction::Set) + .value_parser(["crate", "git", "hg", "pijul", "fossil", "auto"]) .default_value("auto") .help("Method to fetch package."), ) @@ -54,13 +55,13 @@ fn main() { .arg( Arg::new("version") .long("version") - .takes_value(true) + .action(ArgAction::Set) .help("Version to download."), ) .arg( Arg::new("extra") .allow_hyphen_values(true) - .multiple_occurrences(true) + .action(ArgAction::Append) .help("Additional arguments passed to clone command."), ), ) @@ -69,19 +70,19 @@ fn main() { .subcommand_matches("clone") .expect("Expected `clone` subcommand."); - let method = submatches.value_of("method").unwrap(); - let name = submatches.value_of("name").unwrap(); - let version = submatches.value_of("version"); + let method = submatches.get_one::("method").unwrap(); + let name = submatches.get_one::("name").unwrap(); + let version = submatches.get_one::("version"); let extra: Vec<&str> = submatches - .values_of("extra") - .map_or_else(Vec::new, |e| e.collect()); + .get_many::("extra") + .map_or_else(Vec::new, |e| e.map(|x| x.as_str()).collect()); let cloner = cargo_clone::Cloner::new(); let result = cloner.clone( // UNWRAP: The argument parser should guarantee only sane values get passed here cargo_clone::CloneMethodKind::from(method).unwrap(), name, - version, + version.map(|x| x.as_str()), &extra, ); if let Err(e) = result {