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

completions(bash, fish): tweak formatting #650

Merged
merged 8 commits into from
Aug 21, 2022

Conversation

ee7
Copy link
Member

@ee7 ee7 commented Aug 6, 2022

Currently, the completions aren't auto-generated from a Nim source of
truth. Make it easier to scan the fish completions by making them more
similar to the output of configlet --help:

  • Group __fish_use_subcommand completions.
  • Order subcommands and options alphabetically.
  • Align -s, -l, and -d.
  • Always put -xa on its own line.

Also, format the bash completions with shfmt:

shfmt --indent 2 --case-indent --space-redirects --keep-padding

This PR is a bit bikeshed-y, but I claim that the new configlet.fish is more readable than the old configlet.fish. So I think this is marginally worthwhile, at least until we close #638.

The extra whitespace doesn't add binary bloat because we compress the completion scripts at compile time and uncompress them at runtime (see #652).

The configlet help message:

$ configlet --help
[...]
Commands:
  completion  Output a completion script for a given shell
  fmt         Format the exercise '.meta/config.json' files
  generate    Generate Concept Exercise 'introduction.md' files from 'introduction.md.tpl' files
  info        Print some information about the track
  lint        Check the track configuration for correctness
  sync        Check or update Practice Exercise docs, metadata, and tests from 'problem-specifications'.
              Check or populate missing 'files' values for Concept/Practice Exercises from the track 'config.json'.
  uuid        Output new (version 4) UUIDs, suitable for the value of a 'uuid' key

Options for completion:
  -s, --shell <shell>          Choose the shell type (required)
                               Allowed values: b[ash], f[ish], z[sh]

Options for fmt:
  -e, --exercise <slug>        Only operate on this exercise
  -u, --update                 Prompt to write formatted files
  -y, --yes                    Auto-confirm the prompt from --update

Options for info:
  -o, --offline                Do not update the cached 'problem-specifications' data

Options for sync:
  -e, --exercise <slug>        Only operate on this exercise
  -o, --offline                Do not update the cached 'problem-specifications' data
  -u, --update                 Prompt to update the unsynced track data
  -y, --yes                    Auto-confirm prompts from --update for updating docs, filepaths, and metadata
      --docs                   Sync Practice Exercise '.docs/introduction.md' and '.docs/instructions.md' files
      --filepaths              Populate empty 'files' values in Concept/Practice exercise '.meta/config.json' files
      --metadata               Sync Practice Exercise '.meta/config.json' metadata values
      --tests [mode]           Sync Practice Exercise '.meta/tests.toml' files.
                               The mode value specifies how missing tests are handled when using --update.
                               Allowed values: c[hoose], i[nclude], e[xclude] (default: choose)

Options for uuid:
  -n, --num <int>              Number of UUIDs to output

Global options:
  -h, --help                   Show this help message and exit
      --version                Show this tool's version information and exit
  -t, --track-dir <dir>        Specify a track directory to use instead of the current directory
  -v, --verbosity <verbosity>  The verbosity of output.
                               Allowed values: q[uiet], n[ormal], d[etailed] (default: normal)

Format with:

    shfmt -i 2 -ci -sr -kp

`shfmt` usage:

    $ shfmt --version
    3.5.1
    $ shfmt --help
    usage: shfmt [flags] [path ...]

    shfmt formats shell programs. If the only argument is a dash ('-') or no
    arguments are given, standard input will be used. If a given path is a
    directory, all shell scripts found under that directory will be used.

      --version  show version and exit

      -l,  --list      list files whose formatting differs from shfmt's
      -w,  --write     write result to file instead of stdout
      -d,  --diff      error with a diff when the formatting differs
      -s,  --simplify  simplify the code
      -mn, --minify    minify the code to reduce its size (implies -s)

    Parser options:

      -ln, --language-dialect str  bash/posix/mksh/bats, default "auto"
      -p,  --posix                 shorthand for -ln=posix
      --filename str               provide a name for the standard input file

    Printer options:

      -i,  --indent uint       0 for tabs (default), >0 for number of spaces
      -bn, --binary-next-line  binary ops like && and | may start a line
      -ci, --case-indent       switch cases will be indented
      -sr, --space-redirects   redirect operators will be followed by a space
      -kp, --keep-padding      keep column alignment paddings
      -fn, --func-next-line    function opening braces are placed on a separate line

    Utilities:

      -f, --find   recursively find all shell files and print the paths
      --tojson     print syntax tree to stdout as a typed JSON

    For more information, see 'man shfmt' and https://github.com/mvdan/sh.
This splits the subcommand from its options, but I think it's slightly
more readable.
Follow the output of `configlet --help`.
Again, reduce the visual diff between the completions and the output of
`configlet --help`.
Later, this will probably have an argument that suggests integers. For
now, at least put `-x` closer to where `-xa` appears.
@ee7 ee7 marked this pull request as ready for review August 18, 2022 14:08
@ee7 ee7 merged commit d7b5178 into exercism:main Aug 21, 2022
@ee7 ee7 deleted the completions-formatting branch August 21, 2022 09:22
@ee7 ee7 changed the title completions: tweak formatting completions(bash, fish): tweak formatting Aug 21, 2022
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.

completions: consider refactor to generate completions from internal types
2 participants