Skip to content

Commit

Permalink
Bring structopt back, argh doesn't support OsStrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 2, 2020
1 parent 10aecc0 commit e32778b
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 162 deletions.
134 changes: 104 additions & 30 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 @@ -10,7 +10,7 @@ license = "MIT"
include = ["src/**/*", "Cargo.*", "LICENSE", "README.md", "CHANGELOG.md", "!**/*_test/*"]

[dependencies]
argh = "0.1.3"
structopt = "0.3.15"
jwalk = "0.5.0"
byte-unit = "4"
termion = "1.5.2"
Expand Down
26 changes: 10 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::interactive::{Interaction, TerminalApp};
use anyhow::{Context, Result};
use dua::{ByteFormat, Color, TraversalSorting};
use std::{fs, io, io::Write, path::PathBuf, process};
use structopt::StructOpt;
use termion::{raw::IntoRawMode, screen::AlternateScreen};
use tui::backend::TermionBackend;
use tui_react::Terminal;
Expand All @@ -12,9 +13,9 @@ mod interactive;
mod options;

fn main() -> Result<()> {
use options::*;
use options::Command::*;

let opt: options::Args = argh::from_env();
let opt: options::Args = options::Args::from_args();
let walk_options = dua::WalkOptions {
threads: opt.threads.unwrap_or(0),
byte_format: opt.format.map(Into::into).unwrap_or(ByteFormat::Metric),
Expand All @@ -29,8 +30,7 @@ fn main() -> Result<()> {
cross_filesystems: !opt.stay_on_filesystem,
};
let res = match opt.command {
Some(Command::Interactive(Interactive { input }))
| Some(Command::InteractiveAlias(InteractiveAlias { input })) => {
Some(Interactive { input }) => {
let mut terminal = {
let stdout = io::stdout()
.into_raw_mode()
Expand Down Expand Up @@ -59,29 +59,23 @@ fn main() -> Result<()> {
// Exit 'quickly' to avoid having to not have to deal with slightly different types in the other match branches
std::process::exit(res.transpose()?.map(|e| e.to_exit_code()).unwrap_or(0));
}
Some(Command::Aggregate(Aggregate {
Some(Aggregate {
input,
no_total,
no_sort,
stats,
}))
| Some(Command::AggregateAlias(AggregateAlias {
input,
no_total,
no_sort,
stats,
})) => {
statistics,
}) => {
let stdout = io::stdout();
let stdout_locked = stdout.lock();
let (res, statistics) = dua::aggregate(
let (res, stats) = dua::aggregate(
stdout_locked,
walk_options,
!no_total,
!no_sort,
paths_from(input)?,
)?;
if stats {
writeln!(io::stderr(), "{:?}", statistics).ok();
if statistics {
writeln!(io::stderr(), "{:?}", stats).ok();
}
res
}
Expand Down
Loading

0 comments on commit e32778b

Please sign in to comment.