From b029dc5d190b23bf3e3fc95a3947f28f868e674e Mon Sep 17 00:00:00 2001 From: Marcin Puc Date: Sun, 23 Jan 2022 12:22:35 +0100 Subject: [PATCH] Update clap to official release --- Cargo.lock | 15 ++++++------- Cargo.toml | 2 +- src/main.rs | 2 +- src/options.rs | 57 ++++++++++++++++---------------------------------- 4 files changed, 26 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ff66996c..0b8acf73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.0.0-rc.8" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "484f17839417b695a6f4a75c20e49820ba0a1d00aa41ebd8ba0e5dfe0fbc3b74" +checksum = "7a30c3bf9ff12dfe5dae53f0a96e0febcd18420d1c0e7fad77796d9d5c4b5375" dependencies = [ "atty", "bitflags", @@ -93,9 +93,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.0.0-rc.8" +version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a86d4ec799f94ddc4a4a4edf652f89b360219905f86edcb8abe5974dfef135b8" +checksum = "517358c28fcef6607bf6f76108e02afad7e82297d132a6b846dcc1fc3efcd153" dependencies = [ "heck", "proc-macro-error", @@ -318,12 +318,9 @@ checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" [[package]] name = "heck" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" diff --git a/Cargo.toml b/Cargo.toml index 8d29eb22..3c4e5edf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ trash-move = ["trash"] aggregate-scan-progress = [] [dependencies] -clap = { version = "=3.0.0-rc.8", features = ["derive", "cargo"] } +clap = { version = "3.0", features = ["derive"] } jwalk = "0.6.0" byte-unit = "4" atty = "0.2.11" diff --git a/src/main.rs b/src/main.rs index d8720a3b..cd3cf360 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,7 +59,7 @@ fn main() -> Result<()> { let threads = derive_default_threads(opt.threads); let walk_options = dua::WalkOptions { threads, - byte_format: opt.format.map(Into::into).unwrap_or(ByteFormat::Metric), + byte_format: opt.format.into(), apparent_size: opt.apparent_size, count_hard_links: opt.count_hard_links, sorting: TraversalSorting::None, diff --git a/src/options.rs b/src/options.rs index 8eccd395..5431f127 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,8 +1,7 @@ use dua::ByteFormat as LibraryByteFormat; use std::path::PathBuf; -use std::str::FromStr; -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Debug, Clone, Copy, clap::ArgEnum)] pub enum ByteFormat { Metric, Binary, @@ -13,28 +12,6 @@ pub enum ByteFormat { MiB, } -impl FromStr for ByteFormat { - type Err = String; - - fn from_str(s: &str) -> Result { - Ok(match s { - "metric" | "Metric" => ByteFormat::Metric, - "binary" | "Binary" => ByteFormat::Binary, - "bytes" | "Bytes" => ByteFormat::Bytes, - "GB" | "Gb" | "gb" => ByteFormat::GB, - "GiB" | "gib" => ByteFormat::GiB, - "MB" | "Mb" | "mb" => ByteFormat::MB, - "MiB" | "mib" => ByteFormat::MiB, - _ => return Err(format!("Invalid byte format: {:?}", s)), - }) - } -} - -impl ByteFormat { - const VARIANTS: &'static [&'static str] = - &["metric", "binary", "bytes", "MB", "MiB", "GB", "GiB"]; -} - impl From for LibraryByteFormat { fn from(input: ByteFormat) -> Self { match input { @@ -49,33 +26,37 @@ impl From for LibraryByteFormat { } } +/// A tool to learn about disk usage, fast! #[derive(Debug, clap::Parser)] -#[clap(name = "dua", about = "A tool to learn about disk usage, fast!", version = clap::crate_version!())] -#[clap(override_usage = "dua [FLAGS] [OPTIONS] [SUBCOMMAND] [input]...")] +#[clap(name = "dua", version)] +#[clap(override_usage = "dua [FLAGS] [OPTIONS] [SUBCOMMAND] [INPUT]...")] pub struct Args { #[clap(subcommand)] pub command: Option, /// The amount of threads to use. Defaults to 0, indicating the amount of logical processors. /// Set to 1 to use only a single thread. - #[clap(short = 't', long = "threads", default_value = "0")] + #[clap(short = 't', long = "threads", default_value_t = 0)] pub threads: usize, - /// The format with which to print byte counts. - /// Metric - uses 1000 as base (default) - /// Binary - uses 1024 as base - /// Bytes - plain bytes without any formatting - /// GB - only gigabytes - /// GiB - only gibibytes - /// MB - only megabytes + /// The format with which to print byte counts: + /// metric - uses 1000 as base (default), + /// binary - uses 1024 as base, + /// bytes - plain bytes without any formatting, + /// GB - only gigabytes, + /// GiB - only gibibytes, + /// MB - only megabytes, /// MiB - only mebibytes #[clap( short = 'f', long, + arg_enum, + default_value_t = ByteFormat::Metric, ignore_case = true, - possible_values(ByteFormat::VARIANTS) + hide_default_value = true, + hide_possible_values = true )] - pub format: Option, + pub format: ByteFormat, /// Display apparent size instead of disk usage. #[clap(short = 'A', long)] @@ -101,12 +82,11 @@ pub struct Args { pub input: Vec, } -#[derive(Debug, clap::Parser)] +#[derive(Debug, clap::Subcommand)] pub enum Command { /// Launch the terminal user interface #[cfg(any(feature = "tui-unix", feature = "tui-crossplatform"))] #[clap(name = "interactive", visible_alias = "i")] - #[clap(setting = clap::AppSettings::DisableVersionFlag)] Interactive { /// One or more input files or directories. If unset, we will use all entries in the current working directory. #[clap(parse(from_os_str))] @@ -114,7 +94,6 @@ pub enum Command { }, /// Aggregrate the consumed space of one or more directories or files #[clap(name = "aggregate", visible_alias = "a")] - #[clap(setting = clap::AppSettings::DisableVersionFlag)] Aggregate { /// If set, print additional statistics about the file traversal to stderr #[clap(long = "stats")]