Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/uu/cut/src/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,20 +440,18 @@ fn cut_fields<R: Read, W: Write>(
}
}

fn cut_files(mut filenames: Vec<OsString>, mode: &Mode) {
fn cut_files<'a, I>(filenames: I, mode: &Mode)
where
I: IntoIterator<Item = &'a OsString>,
{
let mut stdin_read = false;

if filenames.is_empty() {
filenames.push(OsString::from("-"));
}

let mut out: Box<dyn Write> = if stdout().is_terminal() {
Box::new(stdout())
} else {
Box::new(BufWriter::new(stdout())) as Box<dyn Write>
};

for filename in &filenames {
for filename in filenames {
if filename == "-" {
if stdin_read {
continue;
Expand Down Expand Up @@ -674,12 +672,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
};

let mode = mode_parse.map_err(|e| USimpleError::new(1, e))?;

let files = matches
.get_many::<OsString>(options::FILE)
.unwrap_or_default()
.cloned()
.collect();
#[allow(clippy::unwrap_used, reason = "clap provides '-' by default")]
let files = matches.get_many::<OsString>(options::FILE).unwrap();

cut_files(files, &mode);

Expand Down Expand Up @@ -776,6 +770,7 @@ pub fn uu_app() -> Command {
.hide(true)
.action(ArgAction::Append)
.value_hint(clap::ValueHint::FilePath)
.default_value("-")
.value_parser(clap::value_parser!(OsString)),
)
.arg(
Expand Down
Loading