summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2020-11-15 11:42:45 +0800
committerSebastian Thiel <sebastian.thiel@icloud.com>2020-11-15 11:42:45 +0800
commit5782c4ff99b70ea101ed2f36711a456fd4e4e37b (patch)
tree04a5c4d2f28e42b313d606b366a86c974be104ae
parent88753aa6d6a7d23a7d4334b7913655009adfc079 (diff)
switch from structup to clap 3 beta.2
…to see if the order of arguments is corrected. It's not the case. Related to #71
-rw-r--r--CHANGELOG.md4
-rw-r--r--Cargo.lock79
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs4
-rw-r--r--src/options.rs79
5 files changed, 103 insertions, 65 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ca2c924..ccbaabc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,7 +28,7 @@ See [this PR](https://github.com/Byron/dua-cli/pull/62) for reference.
#### v2.8.2
-* Switch back to `structopt` from `argh` to support non-UTF-8 encoded paths to be passed to dua
+* Switch back to `clap` from `argh` to support non-UTF-8 encoded paths to be passed to dua
I hope that `argh` or an alternative will one day consider supporting os-strings, as it would in theory be an issue
for anyone who passes paths to their command-line tool.
@@ -39,7 +39,7 @@ for anyone who passes paths to their command-line tool.
#### v2.8.0
-* Switched from `structopt` to `argh` for a 300kb reduction in binary size and 1 minute smaller compile times.
+* Switched from `clap` to `argh` for a 300kb reduction in binary size and 1 minute smaller compile times.
#### v2.7.0
diff --git a/Cargo.lock b/Cargo.lock
index ccea108..6064417 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -67,20 +67,37 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
-version = "2.33.3"
+version = "3.0.0-beta.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
+checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142"
dependencies = [
- "ansi_term",
"atty",
"bitflags",
+ "clap_derive",
+ "indexmap",
+ "lazy_static",
+ "os_str_bytes",
"strsim",
+ "termcolor",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
+name = "clap_derive"
+version = "3.0.0-beta.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "370f715b81112975b1b69db93e0b56ea4cd4e5002ac43b2da8474106a54096a1"
+dependencies = [
+ "heck",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "cloudabi"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -285,6 +302,7 @@ dependencies = [
"anyhow",
"atty",
"byte-unit",
+ "clap",
"colored",
"crosstermion",
"filesize",
@@ -294,7 +312,6 @@ dependencies = [
"open",
"petgraph",
"pretty_assertions",
- "structopt",
"tui",
"tui-react 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-segmentation",
@@ -493,6 +510,12 @@ dependencies = [
]
[[package]]
+name = "os_str_bytes"
+version = "2.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85"
+
+[[package]]
name = "output_vt100"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -677,43 +700,28 @@ dependencies = [
[[package]]
name = "strsim"
-version = "0.8.0"
+version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
-
-[[package]]
-name = "structopt"
-version = "0.3.20"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "126d630294ec449fae0b16f964e35bf3c74f940da9dca17ee9b905f7b3112eb8"
-dependencies = [
- "clap",
- "lazy_static",
- "structopt-derive",
-]
+checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
-name = "structopt-derive"
-version = "0.4.13"
+name = "syn"
+version = "1.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "65e51c492f9e23a220534971ff5afc14037289de430e3c83f9daf6a1b6ae91e8"
+checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac"
dependencies = [
- "heck",
- "proc-macro-error",
"proc-macro2",
"quote",
- "syn",
+ "unicode-xid",
]
[[package]]
-name = "syn"
-version = "1.0.48"
+name = "termcolor"
+version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac"
+checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
dependencies = [
- "proc-macro2",
- "quote",
- "unicode-xid",
+ "winapi-util",
]
[[package]]
@@ -730,9 +738,9 @@ dependencies = [
[[package]]
name = "textwrap"
-version = "0.11.0"
+version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
+checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789"
dependencies = [
"unicode-width",
]
@@ -835,6 +843,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
+name = "winapi-util"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 6e21c5b..9079051 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,7 +17,7 @@ tui-crossplatform = ["crosstermion/tui-react-crossterm", "tui-shared"]
tui-shared = ["tui", "tui-react", "open", "unicode-segmentation"]
[dependencies]
-structopt = "0.3.15"
+clap = "3.0.0-beta.2"
jwalk = "0.5.0"
byte-unit = "4"
atty = "0.2.11"
diff --git a/src/main.rs b/src/main.rs
index 09d5704..9313c26 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,8 +1,8 @@
#![forbid(unsafe_code)]
use anyhow::{anyhow, Result};
+use clap::Clap;
use dua::{ByteFormat, TraversalSorting};
use std::{fs, io, io::Write, path::PathBuf, process};
-use structopt::StructOpt;
#[cfg(any(feature = "tui-unix", feature = "tui-crossplatform"))]
mod interactive;
@@ -11,7 +11,7 @@ mod options;
fn main() -> Result<()> {
use options::Command::*;
- let opt: options::Args = options::Args::from_iter(wild::args_os());
+ let opt: options::Args = options::Args::parse_from(wild::args_os());
let walk_options = dua::WalkOptions {
threads: opt.threads.unwrap_or(0),
byte_format: opt.format.map(Into::into).unwrap_or(ByteFormat::Metric),
diff --git a/src/options.rs b/src/options.rs
index a7d7618..d62c199 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -1,20 +1,41 @@
+use clap::Clap;
use dua::ByteFormat as LibraryByteFormat;
use std::path::PathBuf;
-use structopt::{clap::arg_enum, StructOpt};
+use std::str::FromStr;
-arg_enum! {
- #[derive(PartialEq, Debug)]
- pub enum ByteFormat {
- Metric,
- Binary,
- Bytes,
- GB,
- GiB,
- MB,
- MiB
+#[derive(PartialEq, Debug)]
+pub enum ByteFormat {
+ Metric,
+ Binary,
+ Bytes,
+ GB,
+ GiB,
+ MB,
+ MiB,
+}
+
+impl FromStr for ByteFormat {
+ type Err = String;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ 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<ByteFormat> for LibraryByteFormat {
fn from(input: ByteFormat) -> Self {
match input {
@@ -29,16 +50,16 @@ impl From<ByteFormat> for LibraryByteFormat {
}
}
-#[derive(Debug, StructOpt)]
-#[structopt(name = "dua", about = "A tool to learn about disk usage, fast!")]
-#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]
+#[derive(Debug, Clap)]
+#[clap(name = "dua", about = "A tool to learn about disk usage, fast!")]
+#[clap(setting = clap::AppSettings::ColoredHelp)]
pub struct Args {
- #[structopt(subcommand)]
+ #[clap(subcommand)]
pub command: Option<Command>,
/// The amount of threads to use. Defaults to the amount of logical processors.
/// Set to 1 to use only a single thread.
- #[structopt(short = "t", long = "threads")]
+ #[clap(short = 't', long = "threads")]
pub threads: Option<usize>,
/// The format with which to print byte counts.
@@ -49,51 +70,51 @@ pub struct Args {
/// GiB - only gibibytes
/// MB - only megabytes
/// MiB - only mebibytes
- #[structopt(short = "f", long, case_insensitive = true, possible_values(&ByteFormat::variants()))]
+ #[clap(short = 'f', long, case_insensitive = true, possible_values(&ByteFormat::VARIANTS))]
pub format: Option<ByteFormat>,
/// Display apparent size instead of disk usage.
- #[structopt(short = "A", long)]
+ #[clap(short = 'A', long)]
pub apparent_size: bool,
/// Count hard-linked files each time they are seen
- #[structopt(short = "l", long)]
+ #[clap(short = 'l', long)]
pub count_hard_links: bool,
/// If set, we will not cross filesystems or traverse mount points
- #[structopt(short = "x", long)]
+ #[clap(short = 'x', long)]
pub stay_on_filesystem: bool,
/// One or more input files or directories. If unset, we will use all entries in the current working directory.
- #[structopt(parse(from_os_str))]
+ #[clap(parse(from_os_str))]
pub input: Vec<PathBuf>,
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Clap)]
pub enum Command {
/// Launch the terminal user interface
#[cfg(any(feature = "tui-unix", feature = "tui-crossplatform"))]
- #[structopt(name = "interactive", visible_alias = "i")]
+ #[clap(name = "interactive", visible_alias = "i")]
Interactive {
/// One or more input files or directories. If unset, we will use all entries in the current working directory.
- #[structopt(parse(from_os_str))]
+ #[clap(parse(from_os_str))]
input: Vec<PathBuf>,
},
/// Aggregrate the consumed space of one or more directories or files
- #[structopt(name = "aggregate", visible_alias = "a")]
+ #[clap(name = "aggregate", visible_alias = "a")]
Aggregate {
/// If set, print additional statistics about the file traversal to stderr
- #[structopt(long = "stats")]
+ #[clap(long = "stats")]
statistics: bool,
/// If set, paths will be printed in their order of occurrence on the command-line.
/// Otherwise they are sorted by their size in bytes, ascending.
- #[structopt(long)]
+ #[clap(long)]
no_sort: bool,
/// If set, no total column will be computed for multiple inputs
- #[structopt(long)]
+ #[clap(long)]
no_total: bool,
/// One or more input files or directories. If unset, we will use all entries in the current working directory.
- #[structopt(parse(from_os_str))]
+ #[clap(parse(from_os_str))]
input: Vec<PathBuf>,
},
}