sharkdp / hexyl

A command-line hex viewer
Apache License 2.0
8.92k stars 227 forks source link

Argument --length silently takes precedence over --bytes. #105

Closed eth-p closed 3 years ago

eth-p commented 3 years ago

When specifying both --length and --bytes in either long or short form, the value of --length will be chosen while the value specified by --bytes will be discarded silently. While I don't think anybody would intentionally run into it, having a warning or error just in case is something that would help improve UX.

https://github.com/sharkdp/hexyl/blob/cc5b308fc9c2ca57ba176cf69a237f13428bb8e3/src/bin/hexyl.rs#L174-L176


Note: I'm doing a class assignment regarding creating tests (from scratch) for an open-source command line program, and I chose hexyl for it. You might have a couple more of these on the way, depending on what the assignment brings to light :)

sharkdp commented 3 years ago

While I don't think anybody would intentionally run into it, having a warning or error just in case is something that would help improve UX.

That sounds good, yes! We could probably mark them as conflicting (via clap), or as "overrides with".

Note: I'm doing a class assignment regarding creating tests (from scratch) for an open-source command line program, and I chose hexyl for it.

That is an awesome assignment! Thank you for choosing hexyl :+1: :smile:

sharkdp commented 3 years ago

By the way: if someone starts implementing integration-style tests for hexyl, I think we should consider using assert_cmd (similar to how we use it for bat).

A test for this would look similar to:

#[test]
fn fail_if_length_and_bytes_options_are_used_simultaneously() {
    hexyl().arg("--length=10").arg("--bytes=5").assert().failure();
}