Use clap3

This commit is contained in:
Félix Saparelli 2022-06-02 22:25:13 +12:00
parent 6877a0c3a9
commit d58ce3892a
No known key found for this signature in database
GPG key ID: B948C4BAE44FC474
3 changed files with 70 additions and 57 deletions

92
Cargo.lock generated
View file

@ -69,7 +69,7 @@ dependencies = [
"bitflags", "bitflags",
"cexpr", "cexpr",
"clang-sys", "clang-sys",
"clap", "clap 2.34.0",
"env_logger", "env_logger",
"lazy_static", "lazy_static",
"lazycell", "lazycell",
@ -144,6 +144,7 @@ dependencies = [
"async-trait", "async-trait",
"cargo_metadata", "cargo_metadata",
"cargo_toml", "cargo_toml",
"clap 3.1.18",
"crates_io_api", "crates_io_api",
"dirs", "dirs",
"env_logger", "env_logger",
@ -155,7 +156,6 @@ dependencies = [
"semver", "semver",
"serde", "serde",
"simplelog", "simplelog",
"structopt",
"strum", "strum",
"strum_macros", "strum_macros",
"tar", "tar",
@ -257,12 +257,51 @@ dependencies = [
"ansi_term", "ansi_term",
"atty", "atty",
"bitflags", "bitflags",
"strsim", "strsim 0.8.0",
"textwrap 0.11.0", "textwrap 0.11.0",
"unicode-width", "unicode-width",
"vec_map", "vec_map",
] ]
[[package]]
name = "clap"
version = "3.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b"
dependencies = [
"atty",
"bitflags",
"clap_derive",
"clap_lex",
"indexmap",
"lazy_static",
"strsim 0.10.0",
"termcolor",
"textwrap 0.15.0",
]
[[package]]
name = "clap_derive"
version = "3.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213"
dependencies = [
"os_str_bytes",
]
[[package]] [[package]]
name = "cmake" name = "cmake"
version = "0.1.48" version = "0.1.48"
@ -568,15 +607,6 @@ version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]]
name = "heck"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
dependencies = [
"unicode-segmentation",
]
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.4.0" version = "0.4.0"
@ -922,6 +952,12 @@ version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
[[package]]
name = "os_str_bytes"
version = "6.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa"
[[package]] [[package]]
name = "owo-colors" name = "owo-colors"
version = "3.4.0" version = "3.4.0"
@ -1261,28 +1297,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]] [[package]]
name = "structopt" name = "strsim"
version = "0.3.26" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
dependencies = [
"clap",
"lazy_static",
"structopt-derive",
]
[[package]]
name = "structopt-derive"
version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
dependencies = [
"heck 0.3.3",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "strum" name = "strum"
@ -1296,7 +1314,7 @@ version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6878079b17446e4d3eba6192bb0a2950d5b14f0ed8424b852310e5a94345d0ef" checksum = "6878079b17446e4d3eba6192bb0a2950d5b14f0ed8424b852310e5a94345d0ef"
dependencies = [ dependencies = [
"heck 0.4.0", "heck",
"proc-macro2", "proc-macro2",
"quote", "quote",
"rustversion", "rustversion",
@ -1595,12 +1613,6 @@ dependencies = [
"tinyvec", "tinyvec",
] ]
[[package]]
name = "unicode-segmentation"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99"
[[package]] [[package]]
name = "unicode-width" name = "unicode-width"
version = "0.1.9" version = "0.1.9"

View file

@ -22,6 +22,7 @@ pkg-fmt = "zip"
async-trait = "0.1.56" async-trait = "0.1.56"
cargo_metadata = "0.14.2" cargo_metadata = "0.14.2"
cargo_toml = "0.11.4" cargo_toml = "0.11.4"
clap = { version = "3.1.18", features = ["derive"] }
crates_io_api = { version = "0.8.0", default-features = false, features = ["rustls"] } crates_io_api = { version = "0.8.0", default-features = false, features = ["rustls"] }
dirs = "4.0.0" dirs = "4.0.0"
flate2 = { version = "1.0.24", features = ["zlib-ng"], default-features = false } flate2 = { version = "1.0.24", features = ["zlib-ng"], default-features = false }
@ -31,7 +32,6 @@ reqwest = { version = "0.11.10", features = [ "rustls-tls" ], default-features =
semver = "1.0.7" semver = "1.0.7"
serde = { version = "1.0.136", features = [ "derive" ] } serde = { version = "1.0.136", features = [ "derive" ] }
simplelog = "0.12.0" simplelog = "0.12.0"
structopt = "0.3.26"
strum = "0.24.0" strum = "0.24.0"
strum_macros = "0.24.0" strum_macros = "0.24.0"
tar = "0.4.38" tar = "0.4.38"

View file

@ -7,10 +7,10 @@ use std::{
}; };
use cargo_toml::{Package, Product}; use cargo_toml::{Package, Product};
use clap::Parser;
use log::{debug, error, info, warn, LevelFilter}; use log::{debug, error, info, warn, LevelFilter};
use miette::{miette, IntoDiagnostic, Result, WrapErr}; use miette::{miette, IntoDiagnostic, Result, WrapErr};
use simplelog::{ColorChoice, ConfigBuilder, TermLogger, TerminalMode}; use simplelog::{ColorChoice, ConfigBuilder, TermLogger, TerminalMode};
use structopt::StructOpt;
use tempfile::TempDir; use tempfile::TempDir;
use tokio::{process::Command, runtime::Runtime, task::JoinError}; use tokio::{process::Command, runtime::Runtime, task::JoinError};
@ -20,64 +20,65 @@ use cargo_binstall::{
*, *,
}; };
#[derive(Debug, StructOpt)] #[derive(Debug, Parser)]
#[clap(version, about = "Install a Rust binary... from binaries!")]
struct Options { struct Options {
/// Package name or URL for installation /// Package name or URL for installation
/// This must be either a crates.io package name or github or gitlab url /// This must be either a crates.io package name or github or gitlab url
#[structopt()] #[clap(value_name = "crate")]
name: String, name: String,
/// Filter for package version to install, in Cargo.toml format. /// Filter for package version to install, in Cargo.toml format.
/// Use `=1.2.3` to install a specific version. /// Use `=1.2.3` to install a specific version.
#[structopt(long, default_value = "*")] #[clap(long, default_value = "*")]
version: String, version: String,
/// Override binary target, ignoring compiled version /// Override binary target, ignoring compiled version
#[structopt(long, default_value = TARGET)] #[clap(help_heading = "OVERRIDES", long, default_value = TARGET)]
target: String, target: String,
/// Override install path for downloaded binary. /// Override install path for downloaded binary.
/// Defaults to `$HOME/.cargo/bin` /// Defaults to `$HOME/.cargo/bin`
#[structopt(long)] #[clap(help_heading = "OVERRIDES", long)]
install_path: Option<String>, install_path: Option<String>,
/// Disable symlinking / versioned updates /// Disable symlinking / versioned updates
#[structopt(long)] #[clap(long)]
no_symlinks: bool, no_symlinks: bool,
/// Dry run, fetch and show changes without installing binaries /// Dry run, fetch and show changes without installing binaries
#[structopt(long)] #[clap(long)]
dry_run: bool, dry_run: bool,
/// Disable interactive mode / confirmation /// Disable interactive mode / confirmation
#[structopt(long)] #[clap(long)]
no_confirm: bool, no_confirm: bool,
/// Do not cleanup temporary files on success /// Do not cleanup temporary files on success
#[structopt(long)] #[clap(long)]
no_cleanup: bool, no_cleanup: bool,
/// Override manifest source. /// Override manifest source.
/// This skips searching crates.io for a manifest and uses /// This skips searching crates.io for a manifest and uses
/// the specified path directly, useful for debugging and /// the specified path directly, useful for debugging and
/// when adding `binstall` support. /// when adding `binstall` support.
#[structopt(long)] #[clap(help_heading = "OVERRIDES", long)]
manifest_path: Option<PathBuf>, manifest_path: Option<PathBuf>,
/// Utility log level /// Utility log level
#[structopt(long, default_value = "info")] #[clap(long, default_value = "info")]
log_level: LevelFilter, log_level: LevelFilter,
/// Override Cargo.toml package manifest bin-dir. /// Override Cargo.toml package manifest bin-dir.
#[structopt(long)] #[clap(help_heading = "OVERRIDES", long)]
bin_dir: Option<String>, bin_dir: Option<String>,
/// Override Cargo.toml package manifest pkg-fmt. /// Override Cargo.toml package manifest pkg-fmt.
#[structopt(long)] #[clap(help_heading = "OVERRIDES", long)]
pkg_fmt: Option<PkgFmt>, pkg_fmt: Option<PkgFmt>,
/// Override Cargo.toml package manifest pkg-url. /// Override Cargo.toml package manifest pkg-url.
#[structopt(long)] #[clap(help_heading = "OVERRIDES", long)]
pkg_url: Option<String>, pkg_url: Option<String>,
} }
@ -140,7 +141,7 @@ async fn entry() -> Result<()> {
} }
// Load options // Load options
let mut opts = Options::from_iter(args.iter()); let mut opts = Options::parse_from(args.iter());
let cli_overrides = PkgOverride { let cli_overrides = PkgOverride {
pkg_url: opts.pkg_url.take(), pkg_url: opts.pkg_url.take(),
pkg_fmt: opts.pkg_fmt.take(), pkg_fmt: opts.pkg_fmt.take(),