-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
Looks good but please add tests in tests/by-util/test_hashsum.rs |
4f43fab
to
aae056a
Compare
tests/by-util/test_hashsum.rs
Outdated
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() |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
)
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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. |
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
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.
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.
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.
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.
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