mirror of
https://github.com/bootandy/dust.git
synced 2025-12-05 20:40:11 -08:00
Read inputs from stdin when applicable
This commit is contained in:
@@ -131,5 +131,5 @@ pub fn build_cli() -> Command<'static> {
|
||||
.long("si")
|
||||
.help("print sizes in powers of 1000 (e.g., 1.1G)")
|
||||
)
|
||||
.arg(Arg::new("inputs").multiple_occurrences(true).default_value("."))
|
||||
.arg(Arg::new("inputs").multiple_occurrences(true))
|
||||
}
|
||||
|
||||
23
src/main.rs
23
src/main.rs
@@ -11,6 +11,7 @@ mod utils;
|
||||
|
||||
use crate::cli::build_cli;
|
||||
use std::collections::HashSet;
|
||||
use std::io::BufRead;
|
||||
use std::process;
|
||||
use sysinfo::{System, SystemExt};
|
||||
|
||||
@@ -91,14 +92,28 @@ fn get_regex_value(maybe_value: Option<Values>) -> Vec<Regex> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
// Returns a list of lines from stdin or `None` if there's nothing to read
|
||||
fn get_lines_from_stdin() -> Option<Vec<String>> {
|
||||
atty::isnt(atty::Stream::Stdin).then(|| {
|
||||
std::io::stdin()
|
||||
.lock()
|
||||
.lines()
|
||||
.collect::<Result<_, _>>()
|
||||
.expect("Error reading from stdin")
|
||||
})
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let options = build_cli().get_matches();
|
||||
let config = get_config();
|
||||
let stdin_lines = get_lines_from_stdin();
|
||||
|
||||
let target_dirs = options
|
||||
.values_of("inputs")
|
||||
.expect("Should be a default value here")
|
||||
.collect();
|
||||
let target_dirs = match options.values_of("inputs") {
|
||||
Some(values) => values.collect(),
|
||||
None => stdin_lines.as_ref().map_or(vec!["."], |lines| {
|
||||
lines.iter().map(String::as_str).collect()
|
||||
}),
|
||||
};
|
||||
|
||||
let summarize_file_types = options.is_present("types");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user