sharkdp / hexyl

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

Argument `--block-size` does not accept units (or hex numbers), contrary to its helptext description. #111

Closed eth-p closed 2 years ago

eth-p commented 3 years ago

The hexyl --help description for the --block-size argument goes as follows:

        --block-size <SIZE>     Sets the size of the `block` unit to SIZE.
                                Examples: --block-size=1024, --block-size=4kB

However, when I attempt to run hexyl "$(which hexyl)" -n 1block --block-size=4kB, hexyl prints the following error:

Error: failed to parse `--block-size` arg "4kb" as positive integer

Caused by:
    invalid digit found in string

This is caused by the block_size argument being parsed as a positive i64 number, rather than as a data unit:

https://github.com/sharkdp/hexyl/blob/cc5b308fc9c2ca57ba176cf69a237f13428bb8e3/src/bin/hexyl.rs#L133-L142

Side note: If this bug was fixed, how would hexyl handle --block-size=1block? Should it be multiplying it by the default value, or would it be more appropriate to treat as an error to avoid any confusion?

Edit: It also doesn't accept hexadecimal numbers.


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

Side note: If this bug was fixed, how would hexyl handle --block-size=1block? Should it be multiplying it by the default value, or would it be more appropriate to treat as an error to avoid any confusion?

Interesting. I think that should be treated as an error, yes.

ErichDonGubler commented 3 years ago

Disclaimer: I'm interested in resolving this. Right now, I'm just going to triage things, but I hope to have solution after I finish researching and put in my vote for my elections as a US resident.

The issue is valid, and the suggested resolution (where --block-size can have a non-block unit specified, otherwise an error is thrown) sounds great to me.

merkrafter commented 2 years ago

May I give this issue a try? Looks like there is no other activity anymore.

sharkdp commented 2 years ago

Yes, of course. Thank you