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

Rewrite CLI using the derive API #225

Merged
merged 2 commits into from
Jul 16, 2024

Conversation

sorairolake
Copy link
Contributor

@sorairolake sorairolake commented Jul 1, 2024

Change to use clap's derive API to implement CLI. Probably, this should not change the behavior.

However, the help message is changed to:

  • When -h is specified, only the first sentence of the help message for each option is printed.
  • Change the position of the possible values ​​description.

@sharkdp
Copy link
Owner

sharkdp commented Jul 1, 2024

Thank you very much for your contribution!

When -h is specified, only the first sentence of the help message for each option is printed.

This is something we came across in fd as well. This is how we fixed it: sharkdp/fd@36ee44a

Even if `-h` is specified, other than the first sentence will also be
printed.
@sorairolake
Copy link
Contributor Author

sorairolake commented Jul 2, 2024

Changed so that even if -h is specified, other than the first sentence will also be printed.

Difference of the short help output between 16cc5d9 and f8b87cc
 A command-line hex viewer
 
 Usage: hexyl [OPTIONS] [FILE]
 
 Arguments:
-  [FILE]  The file to display. If no FILE argument is given, read from STDIN.
+  [FILE]  The file to display. If no FILE argument is given, read from STDIN
 
 Options:
   -n, --length <N>                Only read N bytes from the input. The N argument can
                                   also include a unit with a decimal prefix (kB, MB, ..)
                                   or binary prefix (kiB, MiB, ..), or can be specified
                                   using a hex number. The short option '-l' can be used as
                                   an alias.
                                   Examples: --length=64, --length=4KiB, --length=0xff
-  -c, --bytes <N>                 An alias for -n/--length
+                                  [aliases: bytes] [short aliases: c]
   -s, --skip <N>                  Skip the first N bytes of the input. The N argument can
-                                  also include a unit (see `--length` for details)
+                                  also include a unit (see `--length` for details).
                                   A negative value is valid and will seek from the end of
                                   the file.
-      --block-size <SIZE>         Sets the size of the `block` unit to SIZE (default is
-                                  512).
-                                  Examples: --block-size=1024, --block-size=4kB
+      --block-size <SIZE>         Sets the size of the `block` unit to SIZE.
+                                  Examples: --block-size=1024, --block-size=4kB [default:
+                                  512]
   -v, --no-squeezing              Displays all input data. Otherwise any number of groups
                                   of output lines which would be identical to the
                                   preceding group of lines, are replaced with a line
-                                  comprised of a single asterisk.
-      --color <WHEN>              When to use colors. The 'auto' mode only displays colors
-                                  if the output goes to an interactive terminal. 'force'
-                                  can be used to override the NO_COLOR environment
-                                  variable. [default: always] [possible values: always,
-                                  auto, never, force]
-      --border <STYLE>            Whether to draw a border with Unicode characters, ASCII
-                                  characters, or none at all [default: unicode] [possible
+                                  comprised of a single asterisk
+      --color <WHEN>              When to use colors [default: always] [possible values:
+                                  always, auto, never, force]
+      --border <STYLE>            Whether to draw a border [default: unicode] [possible
                                   values: unicode, ascii, none]
   -p, --plain                     Display output with --no-characters, --no-position,
-                                  --border=none, and --color=never.
-      --no-characters             Do not show the character panel on the right.
+                                  --border=none, and --color=never
+      --no-characters             Do not show the character panel on the right
   -C, --characters                Show the character panel on the right. This is the
-                                  default, unless --no-characters has been specified.
-      --character-table <FORMAT>  Defines how bytes are mapped to characters:
-                                    "default": show printable ASCII characters as-is, '⋄'
-                                    for NULL bytes, ' ' for space, '_' for other ASCII
-                                    whitespace, '•' for other ASCII characters, and '×'
-                                    for non-ASCII bytes.
-                                    "ascii": show printable ASCII as-is, ' ' for space,
-                                    '.' for everything else.
-                                    "codepage-437": uses code page 437 (for non-ASCII
-                                    bytes).
-                                   [default: default] [possible values: default, ascii,
-                                   codepage-437]
-  -P, --no-position               Whether to display the position panel on the left.
+                                  default, unless --no-characters has been specified
+      --character-table <FORMAT>  Defines how bytes are mapped to characters [default:
+                                  default] [possible values: default, ascii, codepage-437]
+  -P, --no-position               Whether to display the position panel on the left
   -o, --display-offset <N>        Add N bytes to the displayed file position. The N
                                   argument can also include a unit (see `--length` for
-                                  details)
+                                  details).
                                   A negative value is valid and calculates an offset
-                                  relative to the end of the file.
+                                  relative to the end of the file. [default: 0]
       --panels <N>                Sets the number of hex data panels to be displayed.
                                   `--panels=auto` will display the maximum number of hex
                                   data panels based on the current terminal width. By
                                   default, hexyl will show two panels, unless the terminal
-                                  is not wide enough for that.
+                                  is not wide enough for that
   -g, --group-size <N>            Number of bytes/octets that should be grouped together.
-                                  Possible group sizes are 1, 2, 4, 8. The default is 1.
                                   You can use the '--endianness' option to control the
                                   ordering of the bytes within a group. '--groupsize' can
-                                  be used as an alias (xxd-compatibility).
+                                  be used as an alias (xxd-compatibility) [default: 1]
+                                  [possible values: 1, 2, 4, 8]
       --endianness <FORMAT>       Whether to print out groups in little-endian or
                                   big-endian format. This option only has an effect if the
                                   '--group-size' is larger than 1. '-e' can be used as an
-                                  alias for '--endianness=little'. [default: big]
-                                  [possible values: big, little]
+                                  alias for '--endianness=little' [default: big] [possible
+                                  values: little, big]
   -b, --base <B>                  Sets the base used for the bytes. The possible options
-                                  are binary, octal, decimal, and hexadecimal. The default
-                                  base is hexadecimal.
+                                  are binary, octal, decimal, and hexadecimal [default:
+                                  hexadecimal]
       --terminal-width <N>        Sets the number of terminal columns to be displayed.
                                   Since the terminal width may not be an evenly divisible
                                   by the width per hex data column, this will use the
                                   greatest number of hex data panels that can fit in the
                                   requested width but still leave some space to the right.
                                   Cannot be used with other width-setting options.
-  -h, --help                      Print help
+  -h, --help                      Print help (see more with '--help')
   -V, --version                   Print version
The long help output at f8b87cc
A command-line hex viewer

Usage: hexyl [OPTIONS] [FILE]

Arguments:
  [FILE]
          The file to display. If no FILE argument is given, read from STDIN

Options:
  -n, --length <N>
          Only read N bytes from the input. The N argument can also include a unit with a
          decimal prefix (kB, MB, ..) or binary prefix (kiB, MiB, ..), or can be specified
          using a hex number. The short option '-l' can be used as an alias.
          Examples: --length=64, --length=4KiB, --length=0xff
          
          [aliases: bytes]
          [short aliases: c]

  -s, --skip <N>
          Skip the first N bytes of the input. The N argument can also include a unit (see
          `--length` for details).
          A negative value is valid and will seek from the end of the file.

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

  -v, --no-squeezing
          Displays all input data. Otherwise any number of groups of output lines which
          would be identical to the preceding group of lines, are replaced with a line
          comprised of a single asterisk

      --color <WHEN>
          When to use colors
          
          [default: always]

          Possible values:
          - always: Always use colorized output
          - auto:   Only displays colors if the output goes to an interactive terminal
          - never:  Do not use colorized output
          - force:  Override the NO_COLOR environment variable

      --border <STYLE>
          Whether to draw a border
          
          [default: unicode]

          Possible values:
          - unicode: Draw a border with Unicode characters
          - ascii:   Draw a border with ASCII characters
          - none:    Do not draw a border at all

  -p, --plain
          Display output with --no-characters, --no-position, --border=none, and
          --color=never

      --no-characters
          Do not show the character panel on the right

  -C, --characters
          Show the character panel on the right. This is the default, unless
          --no-characters has been specified

      --character-table <FORMAT>
          Defines how bytes are mapped to characters
          
          [default: default]

          Possible values:
          - default:      Show printable ASCII characters as-is, '⋄' for NULL bytes, ' '
            for space, '_' for other ASCII whitespace, '•' for other ASCII characters, and
            '×' for non-ASCII bytes
          - ascii:        Show printable ASCII as-is, ' ' for space, '.' for everything
            else
          - codepage-437: Uses code page 437 (for non-ASCII bytes)

  -P, --no-position
          Whether to display the position panel on the left

  -o, --display-offset <N>
          Add N bytes to the displayed file position. The N argument can also include a
          unit (see `--length` for details).
          A negative value is valid and calculates an offset relative to the end of the
          file.
          
          [default: 0]

      --panels <N>
          Sets the number of hex data panels to be displayed. `--panels=auto` will display
          the maximum number of hex data panels based on the current terminal width. By
          default, hexyl will show two panels, unless the terminal is not wide enough for
          that

  -g, --group-size <N>
          Number of bytes/octets that should be grouped together. You can use the
          '--endianness' option to control the ordering of the bytes within a group.
          '--groupsize' can be used as an alias (xxd-compatibility)
          
          [default: 1]

          Possible values:
          - 1: Grouped together every byte/octet
          - 2: Grouped together every 2 bytes/octets
          - 4: Grouped together every 4 bytes/octets
          - 8: Grouped together every 8 bytes/octets

      --endianness <FORMAT>
          Whether to print out groups in little-endian or big-endian format. This option
          only has an effect if the '--group-size' is larger than 1. '-e' can be used as
          an alias for '--endianness=little'
          
          [default: big]

          Possible values:
          - little: Print out groups in little-endian format
          - big:    Print out groups in big-endian format

  -b, --base <B>
          Sets the base used for the bytes. The possible options are binary, octal,
          decimal, and hexadecimal
          
          [default: hexadecimal]

      --terminal-width <N>
          Sets the number of terminal columns to be displayed.
          Since the terminal width may not be an evenly divisible by the width per hex
          data column, this will use the greatest number of hex data panels that can fit
          in the requested width but still leave some space to the right.
          Cannot be used with other width-setting options.

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much! This looks much cleaner now.

@sharkdp sharkdp merged commit d2cc025 into sharkdp:master Jul 16, 2024
14 checks passed
@sorairolake sorairolake deleted the rewrite-in-derive-api branch July 16, 2024 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants