mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Read inputs from stdin when applicable
This commit is contained in:
+1
-1
@@ -131,5 +131,5 @@ pub fn build_cli() -> Command<'static> {
|
|||||||
.long("si")
|
.long("si")
|
||||||
.help("print sizes in powers of 1000 (e.g., 1.1G)")
|
.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))
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-4
@@ -11,6 +11,7 @@ mod utils;
|
|||||||
|
|
||||||
use crate::cli::build_cli;
|
use crate::cli::build_cli;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
use std::io::BufRead;
|
||||||
use std::process;
|
use std::process;
|
||||||
use sysinfo::{System, SystemExt};
|
use sysinfo::{System, SystemExt};
|
||||||
|
|
||||||
@@ -91,14 +92,28 @@ fn get_regex_value(maybe_value: Option<Values>) -> Vec<Regex> {
|
|||||||
.collect()
|
.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() {
|
fn main() {
|
||||||
let options = build_cli().get_matches();
|
let options = build_cli().get_matches();
|
||||||
let config = get_config();
|
let config = get_config();
|
||||||
|
let stdin_lines = get_lines_from_stdin();
|
||||||
|
|
||||||
let target_dirs = options
|
let target_dirs = match options.values_of("inputs") {
|
||||||
.values_of("inputs")
|
Some(values) => values.collect(),
|
||||||
.expect("Should be a default value here")
|
None => stdin_lines.as_ref().map_or(vec!["."], |lines| {
|
||||||
.collect();
|
lines.iter().map(String::as_str).collect()
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
let summarize_file_types = options.is_present("types");
|
let summarize_file_types = options.is_present("types");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user