Skip to content

Commit

Permalink
Merge pull request #2428 from jhscheer/cut_2424
Browse files Browse the repository at this point in the history
cut: fix `-d=` (#2424)
  • Loading branch information
sylvestre authored Jun 19, 2021
2 parents 7739080 + 65f47be commit e2a00b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/uu/cut/src/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,16 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
let zero_terminated = matches.is_present(options::ZERO_TERMINATED);

match matches.value_of(options::DELIMITER) {
Some(delim) => {
Some(mut delim) => {
// GNU's `cut` supports `-d=` to set the delimiter to `=`.
// Clap parsing is limited in this situation, see:
// https://github.com/uutils/coreutils/issues/2424#issuecomment-863825242
// Since clap parsing handles `-d=` as delimiter explicitly set to "" and
// an empty delimiter is not accepted by GNU's `cut` (and makes no sense),
// we can use this as basis for a simple workaround:
if delim.is_empty() {
delim = "=";
}
if delim.chars().count() > 1 {
Err(msg_opt_invalid_should_be!(
"empty or 1 character long",
Expand Down
9 changes: 9 additions & 0 deletions tests/by-util/test_cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,12 @@ fn test_directory_and_no_such_file() {
.run()
.stderr_is("cut: some: No such file or directory\n");
}

#[test]
fn test_equal_as_delimiter() {
new_ucmd!()
.args(&["-f", "2", "-d="])
.pipe_in("--libdir=./out/lib")
.succeeds()
.stdout_only("./out/lib\n");
}

0 comments on commit e2a00b6

Please sign in to comment.