Skip to content

Commit

Permalink
switch from structup to clap 3 beta.2
Browse files Browse the repository at this point in the history
…to see if the order of arguments is corrected.
It's not the case.

Related to #71
  • Loading branch information
Byron committed Nov 15, 2020
1 parent 88753aa commit 5782c4f
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 65 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
79 changes: 48 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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),
Expand Down
79 changes: 50 additions & 29 deletions src/options.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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.
Expand All @@ -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>,
},
}

0 comments on commit 5782c4f

Please sign in to comment.