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

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

Closed
eth-p opened this issue Oct 27, 2020 · 4 comments · Fixed by #144
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@eth-p
Copy link

eth-p commented Oct 27, 2020

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

@eth-p eth-p changed the title Argument --block-size does not accept units, contrary to its helptext description. Argument --block-size does not accept units (or hex numbers), contrary to its helptext description. Oct 27, 2020
@sharkdp sharkdp added bug Something isn't working good first issue Good for newcomers labels Oct 29, 2020
@sharkdp
Copy link
Owner

sharkdp commented Oct 29, 2020

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
Copy link
Contributor

ErichDonGubler commented Oct 30, 2020

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
Copy link
Contributor

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

@sharkdp
Copy link
Owner

sharkdp commented Nov 7, 2021

Yes, of course. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants