diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-01 20:09:30 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-01 20:14:31 +0530 |
commit | ae0182f09c0e2c3c77298cb431421cbdc64c0fa8 (patch) | |
tree | dad6439c32112bc69ddcf510693c68dc69326e42 /src | |
parent | a53c2acb65457df740f3605124b9e42d363897de (diff) |
Simplified handling of 'no paths given' casev1.1.0
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 28 | ||||
-rw-r--r-- | src/options.rs | 4 |
2 files changed, 27 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 33d108c..66ec8f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,8 @@ use structopt::StructOpt; use dua::{ByteFormat, Color}; use failure::Error; use failure_tools::ok_or_exit; -use std::{io, io::Write, path::PathBuf, process}; +use std::path::PathBuf; +use std::{fs, io, io::Write, process}; mod options; @@ -34,7 +35,17 @@ fn run() -> Result<(), Error> { statistics, }) => ( statistics, - dua::aggregate(stdout_locked, walk_options, !no_total, !no_sort, input)?, + dua::aggregate( + stdout_locked, + walk_options, + !no_total, + !no_sort, + if input.len() == 0 { + cwd_dirlist()? + } else { + input + }, + )?, ), None => ( false, @@ -44,7 +55,7 @@ fn run() -> Result<(), Error> { true, true, if opt.input.len() == 0 { - vec![PathBuf::from(".")] + cwd_dirlist()? } else { opt.input }, @@ -61,6 +72,17 @@ fn run() -> Result<(), Error> { Ok(()) } +fn cwd_dirlist() -> Result<Vec<PathBuf>, io::Error> { + let mut v: Vec<_> = fs::read_dir(".")? + .filter_map(|e| { + e.ok() + .and_then(|e| e.path().strip_prefix(".").ok().map(ToOwned::to_owned)) + }) + .collect(); + v.sort(); + Ok(v) +} + fn main() { ok_or_exit(run()) } diff --git a/src/options.rs b/src/options.rs index 5c30573..76c0abc 100644 --- a/src/options.rs +++ b/src/options.rs @@ -40,7 +40,7 @@ pub struct Args { #[structopt(short = "f", long = "format")] pub format: Option<ByteFormat>, - /// One or more input files. If unset, we will assume the current directory + /// One or more input files. If unset, we will use all entries in the current working directory. #[structopt(parse(from_os_str))] pub input: Vec<PathBuf>, } @@ -60,7 +60,7 @@ pub enum Command { /// If set, no total column will be computed for multiple inputs #[structopt(long = "no-total")] no_total: bool, - /// One or more input files. If unset, we will assume the current directory + /// One or more input files. If unset, we will use all entries in the current working directory. #[structopt(parse(from_os_str))] input: Vec<PathBuf>, }, |