From 0078c263154106c7418efee4b315a07e32eb5145 Mon Sep 17 00:00:00 2001 From: oech3 <> Date: Sun, 4 Jan 2026 16:26:57 +0900 Subject: [PATCH] hashsum, cksum: Move default stdin to clap --- src/uu/cksum/src/cksum.rs | 16 ++++++++-------- src/uu/hashsum/src/hashsum.rs | 13 +++++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 70c80ae37c7..447e90954f7 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -7,8 +7,7 @@ use clap::builder::ValueParser; use clap::{Arg, ArgAction, Command}; -use std::ffi::{OsStr, OsString}; -use std::iter; +use std::ffi::OsString; use uucore::checksum::compute::{ ChecksumComputeOptions, figure_out_output_format, perform_checksum_computation, }; @@ -121,12 +120,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let length = maybe_sanitize_length(algo_cli, input_length)?; - let files = matches.get_many::(options::FILE).map_or_else( - // No files given, read from stdin. - || Box::new(iter::once(OsStr::new("-"))) as Box>, - // At least one file given, read from them. - |files| Box::new(files.map(OsStr::new)) as Box>, - ); + // clap provides the default value -. So we unwrap() safety. + let files = matches + .get_many::(options::FILE) + .unwrap() + .map(|s| s.as_os_str()); if check { // cksum does not support '--check'ing legacy algorithms @@ -200,6 +198,8 @@ pub fn uu_app() -> Command { .hide(true) .action(ArgAction::Append) .value_parser(ValueParser::os_string()) + .default_value("-") + .hide_default_value(true) .value_hint(clap::ValueHint::FilePath), ) .arg( diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index eea434d9477..3bc6dcff5b2 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -163,12 +163,11 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { let strict = matches.get_flag("strict"); let status = matches.get_flag("status"); - let files = matches.get_many::(options::FILE).map_or_else( - // No files given, read from stdin. - || Box::new(iter::once(OsStr::new("-"))) as Box>, - // At least one file given, read from them. - |files| Box::new(files.map(OsStr::new)) as Box>, - ); + // clap provides the default value -. So we unwrap() safety. + let files = matches + .get_many::(options::FILE) + .unwrap() + .map(|s| s.as_os_str()); if check { // on Windows, allow --binary/--text to be used with --check @@ -340,6 +339,8 @@ pub fn uu_app_common() -> Command { .index(1) .action(ArgAction::Append) .value_name(options::FILE) + .default_value("-") + .hide_default_value(true) .value_hint(clap::ValueHint::FilePath) .value_parser(ValueParser::os_string()), )