From 0ac860657707a42b30450ce499e562209710a833 Mon Sep 17 00:00:00 2001 From: wolimst <64784258+wolimst@users.noreply.github.com> Date: Fri, 9 Feb 2024 22:15:18 +0900 Subject: [PATCH] cut: add comments about handling multiple cutting mode args --- src/uu/cut/src/cut.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index f37716258..cf94a1bd0 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -359,6 +359,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let complement = matches.get_flag(options::COMPLEMENT); + // Only one, and only one of cutting mode arguments, i.e. `-b`, `-c`, `-f`, + // is expected. The number of those arguments is used for parsing a cutting + // mode and handling the error cases. let mode_args_count = [ matches.indices_of(options::BYTES), matches.indices_of(options::CHARACTERS), @@ -521,6 +524,13 @@ pub fn uu_app() -> Command { .about(ABOUT) .after_help(AFTER_HELP) .infer_long_args(true) + // While `args_override_self(true)` for some arguments, such as `-d` + // and `--output-delimiter`, is consistent to the behavior of GNU cut, + // arguments related to cutting mode, i.e. `-b`, `-c`, `-f`, should + // cause an error when there is more than one of them, as described in + // the manual of GNU cut: "Use one, and only one of -b, -c or -f". + // `ArgAction::Append` is used on `-b`, `-c`, `-f` arguments, so that + // the occurrences of those could be counted and be handled accordingly. .args_override_self(true) .arg( Arg::new(options::BYTES)