-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
feat: make signs significant for byte offsets #99
feat: make signs significant for byte offsets #99
Conversation
This looks great - thank you very much (again)!
If a command-line option is harder to understand, I am a fan of (potentially longer) descriptive
🎉
Maybe this would help: https://docs.rs/clap/2.33.1/clap/enum.ArgSettings.html#variant.AllowLeadingHyphen ? There is also "allow negative numbers", but I'm afraid that won't work here due to the trailing unit. |
I added a commit that uses
...as opposed to the more helpful text before:
Since these changes are forwards-compatible anyway, maybe it'd be best to defer thinking about |
I've also added some (teeny) docs indicated where negative values are allowed. There's not a lot of complexity in thinking about just those -- positive relative offsets aren't really exposed anywhere (yet), but they will be when and if range notation is accepted in the form I understand it (i.e., |
Due to
This leaves This sort of behavior is probably why |
Yeah, I'm very much in favor of deferring this parsing problem for later, since whatever solution if viable should in my mind have no regressions. Meanwhile, this problem is perfectly forwards compatible for now. It's a lot easier to simply document the behavior that is very easy to work around right now. |
Ok, so let's remove |
@sharkdp: You interpreted correctly, sorry, I just haven't made this a priority yet what with starting a new job. I should be able to fix this in the next few days, though. |
There is absolutely no hurry (and never will be). Thank you for the updates. |
2da93bc
to
51b002d
Compare
I've removed the commit enabling |
Looks like CI is failing for |
51b002d
to
5eb81a7
Compare
This has happened several times and I'm not entirely sure why. I fixed it for now by switching (back) to |
Thank you for the updates! |
I do NOT consider this ready to merge because documentation doesn't teach about signs and the new distinction that now exists between byte COUNTS, where a positive integer is the goal (like before), and byte OFFSETS, where sign and relativity are now significant. I'm not sure what the best approach to teaching about this would be, and wanted to file this PR in this incomplete state to get feedback and thoughts.What these changes allow is for relative and, in particular, negative byte offsets to be significant and useful in the context of seeking backwards from a
seek
able source like a file. For instance, if one wishes to view the last block of a file to view a footer (not uncommon in custom binary formats), it's now possible to do:...instead of whatever gymnastics users may have done with other commands to calculate the backwards offset as a positive forward offset manually. ~~N.B. that this, unfortunately, will fail:
...because
clap
interprets-1block
as a separate, unrecognized flag.~~EDIT: a solution has been found for allowing offset flags and their values to be separate and still parse negative values correctly via
allow_hyphen_values
, but I have a concern about diagnostics.