sharkdp / hexyl

A command-line hex viewer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

eth-p opened this issue · comments

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:

hexyl/src/bin/hexyl.rs

Lines 133 to 142 in cc5b308

bs.parse::<i64>()
.map_err(|e| anyhow!(e))
.and_then(|x| {
PositiveI64::new(x)
.ok_or_else(|| anyhow!("negative block sizes don't make sense"))
})
.context(anyhow!(
"failed to parse `--block-size` arg {:?} as positive integer",
bs
))

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 :)

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.

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.

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

Yes, of course. Thank you