Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hashsum: add --no-names option from official b3sum tool #3361

Merged
merged 3 commits into from
Apr 6, 2022

Conversation

pothos
Copy link
Contributor

@pothos pothos commented Apr 3, 2022

The official b3sum tool has a --no-names option for only printing the
hashes, omitting the filenames. This is quite handy when used from
scripts because it spares the postprocessing with "cut" or "awk".
Since the installed b3sum symlink would also serve as a drop-in for the
official tool, the --no-names option is expected to exist for
compatibility.

Add a --no-names option not only for b3sum but for hashsum in general
(and maybe GNU coreutils will also feel inspired to add this option).

Closes #3360

@sylvestre
Copy link
Contributor

Looks good but please add tests in tests/by-util/test_hashsum.rs
Looks at other test_*.rs for similar examples of test arguments

@pothos pothos force-pushed the hashsum-no-names branch 2 times, most recently from 4f43fab to aae056a Compare April 3, 2022 21:23
let ts = TestScenario::new("hashsum");
// EXPECTED_FILE has no newline character but the tool output has a newline character
assert_eq!(ts.fixtures.read(EXPECTED_FILE),
ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).arg("--no-names").arg("input.txt").succeeds().no_stderr().stdout_str()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure that rustfmt is going to complain :)

Copy link
Contributor Author

@pothos pothos Apr 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to make it complain but it's quite liberal about linebreaks and indention in this case, or?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rustfmt tests/by-util/test_hashsum.rs passes without any changes (rustfmt 1.4.38-stable (9d1b210 2022-02-23))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check the next CI results for details, not sure if I should move the ); up to the end of the line and so on. Maybe because we are in a macro rustfmt can't operate as usual in my case?

@@ -29,6 +29,15 @@ macro_rules! test_digest {
get_hash!(ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).pipe_in_fixture("input.txt").succeeds().no_stderr().stdout_str()));
}

#[test]
fn test_nonames() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a test with different files at the same time ?

ex
hashsum --no-names input1.txt input2.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, how about covering the special - at the same time, i.e., hashsum --no-names input.txt - with input.txt also piped through stdin? I've pushed this now.

@pothos pothos force-pushed the hashsum-no-names branch from aae056a to f47078b Compare April 3, 2022 21:36
@tertsdiepraam
Copy link
Member

Sylvestre, before you merge this, you might want to consider that this change is not in GNU coreutils. This is compatibility with a separate b3sum utility which GNU does not include. However, I think we should merge it anyway.

pothos and others added 3 commits April 4, 2022 21:41
The official b3sum tool has a --no-names option for only printing the
hashes, omitting the filenames. This is quite handy when used from
scripts because it spares the postprocessing with "cut" or "awk".
Since the installed b3sum symlink would also serve as a drop-in for the
official tool, the --no-names option is expected to exist for
compatibility.

Add a --no-names option not only for b3sum but for hashsum in general
(and maybe GNU coreutils will also feel inspired to add this option).

Closes uutils#3360
@pothos pothos force-pushed the hashsum-no-names branch from 5240351 to 133702a Compare April 4, 2022 19:41
@sylvestre sylvestre merged commit e894e40 into uutils:main Apr 6, 2022
str4d added a commit to str4d/coreutils that referenced this pull request Jun 4, 2022
Several binaries have been added to `hashsum` that have never been part
of GNU Coreutils:

- `sha3*sum` (uutils#869)
- `shake*sum` (uutils#987)
- `b3sum` (uutils#3108 and uutils#3164)

In particular, the `--bits` option, and the `--no-names` option added in
uutils#3361, are not valid for any GNU Coreutils `*sum` binary
(as of Coreutils 9.0).

This commit refactors the argument parsing so that `--bits` and
`--no-names` become invalid options for the binaries intended to match
the GNU Coreutils API, instead of being ignored options. It also
refactors the custom binary name handling to distinguish between
binaries intended to match the GNU Coreutils API, and binaries that
don't have that constraint.

Part of uutils#2930.
str4d added a commit to str4d/coreutils that referenced this pull request Jun 4, 2022
Several binaries have been added to `hashsum` that have never been part
of GNU Coreutils:

- `sha3*sum` (uutils#869)
- `shake*sum` (uutils#987)
- `b3sum` (uutils#3108 and uutils#3164)

In particular, the `--bits` option, and the `--no-names` option added in
uutils#3361, are not valid for any GNU Coreutils `*sum` binary
(as of Coreutils 9.0).

This commit refactors the argument parsing so that `--bits` and
`--no-names` become invalid options for the binaries intended to match
the GNU Coreutils API, instead of being ignored options. It also
refactors the custom binary name handling to distinguish between
binaries intended to match the GNU Coreutils API, and binaries that
don't have that constraint.

Part of uutils#2930.
str4d added a commit to str4d/coreutils that referenced this pull request Jun 5, 2022
Several binaries have been added to `hashsum` that have never been part
of GNU Coreutils:

- `sha3*sum` (uutils#869)
- `shake*sum` (uutils#987)
- `b3sum` (uutils#3108 and uutils#3164)

In particular, the `--bits` option, and the `--no-names` option added in
uutils#3361, are not valid for any GNU Coreutils `*sum` binary
(as of Coreutils 9.0).

This commit refactors the argument parsing so that `--bits` and
`--no-names` become invalid options for the binaries intended to match
the GNU Coreutils API, instead of being ignored options. It also
refactors the custom binary name handling to distinguish between
binaries intended to match the GNU Coreutils API, and binaries that
don't have that constraint.

Part of uutils#2930.
sylvestre pushed a commit to str4d/coreutils that referenced this pull request Jun 10, 2022
Several binaries have been added to `hashsum` that have never been part
of GNU Coreutils:

- `sha3*sum` (uutils#869)
- `shake*sum` (uutils#987)
- `b3sum` (uutils#3108 and uutils#3164)

In particular, the `--bits` option, and the `--no-names` option added in
uutils#3361, are not valid for any GNU Coreutils `*sum` binary
(as of Coreutils 9.0).

This commit refactors the argument parsing so that `--bits` and
`--no-names` become invalid options for the binaries intended to match
the GNU Coreutils API, instead of being ignored options. It also
refactors the custom binary name handling to distinguish between
binaries intended to match the GNU Coreutils API, and binaries that
don't have that constraint.

Part of uutils#2930.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

b3sum/hashsum lacks --no-names argument
3 participants