Commit Graph
52 Commits
Author SHA1 Message Date
cuishuang e4f0e8a092 fix some typos
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-05-18 20:10:29 +02:00
Shun Sakai 7da04c6bff Change -l to conflict with -n and -c 2022-03-25 22:00:40 +01:00
Shun Sakai c497c1fac9 Fix Clippy warnings 2022-03-25 22:00:40 +01:00
merkrafter d1ae68585f Make code compatible with rust 1.46 2021-11-14 09:26:21 +01:00
merkrafter 7a225fe732 Apply clippy suggestions 2021-11-14 09:26:21 +01:00
merkrafter 1b33e516d9 Move hex number processing into own function 2021-11-14 09:26:21 +01:00
merkrafter 55d02c933a Move sign (+/-) processing into own function 2021-11-14 09:26:21 +01:00
merkrafter 51b28ed0b0 Allow hex numbers for --block-size 2021-11-14 09:26:21 +01:00
merkrafter 825100c6d6 Deny 'block' as unit for --block-size 2021-11-14 09:26:21 +01:00
merkrafter 1b1fc4b053 Allow units for --block-size 2021-11-14 09:26:21 +01:00
merkrafter c3dd4e871e Use extraction function for length arg parsing 2021-11-14 09:26:21 +01:00
merkrafter 923bceffaa Add function to extract num and unit from string
Having this as an own function allows special handling of the
'block' unit in --block-size argument.
2021-11-14 09:26:21 +01:00
merkrafter 2942d2419f Introduce enum for byte size units 2021-11-14 09:26:21 +01:00
merkrafter 37d4180f9a Refactor default block size into constant 2021-11-14 09:26:21 +01:00
Mark Umnus 99435cd215 Mention ability to specify length in hex 2021-10-20 22:52:01 +02:00
David Peter 3489998c67 cargo fmt 2021-07-11 20:09:28 +02:00
David Peter 6da15cd1e9 Added alias notice in help text 2021-07-11 19:57:55 +02:00
TheDoctor314 19d2805729 Add alias '-l' for '-n/--length'
Set `.hidden(true)` option

This won't clutter the help text too much.
2021-07-11 19:57:55 +02:00
Mihir Gadgil 532eab762d Fix #131
Don't print the error for version output, instead add a newline print.
Move the eprint for help only.
2021-05-07 10:05:16 +02:00
sharkdp 8c3f2230c6 Better error message when seek fails
> hexyl "$(which hexyl)" --skip=-5gib
    Error: Failed to jump to the desired input position. This could be
    caused by a negative offset that is too large or by an input that is not
    seek-able (e.g. if the input comes from a pipe).

ref: #114
2020-11-01 22:56:59 +01:00
sharkdp afb249e854 Run cargo fmt 2020-11-01 21:04:39 +01:00
sharkdp 9432677d3a Disallow block sizes of 0
closes #110
2020-10-31 10:17:19 +01:00
Tom Milligan 524a6c607f bin: offset should add to skip, not override it 2020-10-31 10:00:03 +01:00
sharkdp bb6a3c0650 Add test for --length, fix #105 2020-10-30 10:07:24 +01:00
Erich Gubler 153b1cccdf feat: make signs significant for byte offsets 2020-08-15 14:11:10 +02:00
Erich Gubler 13aec946a3 improvement: make diagnostics for flags involving byte count parsing actually good
This adds an error type called `ByteCountParseError` with a vanilla
`std::error::Error` implementation. The code could be significantly
compressed with a dependency like `thiserror`.

I opted to implement a separate error type for `parse_byte_count` rather
than using `anyhow`'s small ecosystem of error types there (though they
are used in `<binary>::run`) because it allows pairing diagnostic
results with tests, incl. those already written. This can be helpful in
preventing regressions in error diagnostics.
2020-06-17 18:05:42 +02:00
Erich Gubler e0da7b3f82 style: normalize indentation of doc strings literals for args help 2020-06-17 18:05:42 +02:00
Erich Gubler e29a63358d improvement: elide type of reader 2020-06-17 18:05:42 +02:00
Erich Gubler 2bdf5d768f feat: use anyhow for more structured error messages and better error reporting flexibility
This significantly changes the structure of potential output of
top-level errors.  Before, errors that have a `source` were printed on a
single line, with the `source` omitted. Now, an error with a `source`
will be printed like:

```
Error: <`Display` impl of error>

Caused by:
    <`Display` impl of `source` error>
```

If there are multiple `source` errors in a chain, then it will be of the
form:

```
Error: <`Display` impl of error>

Caused by:
    0: <`Display` impl of first `source` error>
    1: <`Display` impl of `source` of `source` error>
    # etc.
```

Now, in practice this never happened before, since the only error
type that ever could return from `<binary>::run` was `std::io::Error`,
which has no `source`. However, `source`s can start being added if, say,
future work involved using `anyhow::Context::context` or custom errors
that implement `std::Error::source` are added to the codebase. I believe
this is a good choice going forward, but I definitely want to foster
discussion and acceptance for it in the open first!
2020-06-17 18:05:42 +02:00
sharkdp a7892881f3 Wrap help text at 90 characters 2020-06-08 23:19:56 +02:00
sharkdp 3ca002638c Improve help text 2020-06-07 15:12:35 +02:00
sharkdp ccfceaf58c Minor formatting 2020-06-07 15:12:35 +02:00
sharkdp 751b670d5b Fix clippy suggestions 2020-06-07 15:12:35 +02:00
Erich Gubler ddc3a5c04a BREAKING CHANGE: improvement: change byte counts to be a positive i64 (with newtype PositiveI64) instead of a u64 to take advantage of new skip impl for --seek with non-Seek Inputs like STDIN
This is technically a breaking change because it halves the upper range
of accepted values for byte counts. I thought that fine under the
assumption it will be rare for users to ever want to specify something
in the upper half of `u64`'s value range, especially considering that
this can pave the way for having negative byte offsets (instead of just
counts).
2020-06-07 11:08:01 +02:00
Erich Gubler 6d5c61b671 BREAKING CHANGE: improvement(lib): use u64 for Printer::display_offset and Squeezer::process, not usize
Technically a breaking change for architectures where
`size_of::<usize>() > size_of::<u64>()`, but that strikes me as
extremely unlikely.

This change is important because most file seek offsets, even on older
architectures with word sizes smaller than `u32`, accept a `u64`. In
particular, Rust's own `std` acknowledges this. So, we're actually going
against prior art in Rust by using a `usize`.
2020-06-07 11:08:01 +02:00
Erich Gubler 1459616d27 improvement: use or instead of unwrap_or_else for display_offset 2020-06-07 11:08:01 +02:00
Erich Gubler 07cdc97e74 improvement: replace trim_start_matches with slicing op 2020-05-28 18:43:53 +02:00
Erich Gubler bcca1fae03 feat: add block unit and block-size option 2020-05-28 18:43:53 +02:00
Erich Gubler 48ad95efe6 feat: add units system to decimals with {k,m,g,t}[[i]b] support 2020-05-28 18:43:53 +02:00
Erich Gubler 3b3889967c refactor: extract "0x" literal into HEX_PREFIX 2020-05-28 18:43:53 +02:00
Erich Gubler 57f1fb4dc4 BREAKING CHANGE: improvement: disallow leading '+' after "0x" prefix for u64 parse 2020-05-28 18:43:53 +02:00
Erich Gubler ef40be0d53 improvement: fix or_fun_call lint from clippy 2020-05-28 18:43:53 +02:00
Erich Gubler 6b235b1d2e improvement: remove unused atty import 2020-05-28 18:43:53 +02:00
Mario Reder c336259159 skip option error messages and display offset 2020-05-13 18:55:24 +02:00
sharkdp 133fdd9156 Remove unnecessary RefCell, backport to Rust 1.36 2020-05-13 18:55:24 +02:00
Mario Reder 244f71691d feat: add skip option
resolves #16 and #87
2020-05-13 18:55:24 +02:00
sharkdp f71ad1e00d Remove Ctrl-C handler, fixes #84 2020-03-09 20:20:12 +01:00
Tom Milligan d64053771c hexyl: add display offset option 2019-10-07 23:36:53 +02:00
Tom Milligan 622a084ea6 run: factor out mainloop and add tests 2019-07-17 19:31:37 +02:00
Tom Milligan 4c48eedb18 printer: accept any Write as output 2019-07-17 19:31:37 +02:00