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

completion: add configlet completion subcommand #631

Merged
merged 7 commits into from
Aug 6, 2022

Conversation

ee7
Copy link
Member

@ee7 ee7 commented Jul 29, 2022

With this commit, running e.g.

configlet completion --shell fish

will output the fish completion script to stdout. This allows us to
distribute completion scripts to the user without adding them to the
release assets, which avoids cluttering every directory in which the
user runs fetch-configlet.

For example, the user can enable completions for fish by running:

configlet completion -s fish > ~/.config/fish/completions/configlet.fish

Closes: #630


$ ./configlet completion --shell fish
# global options
complete -c configlet -s h -l help -f -d "Show help"
complete -c configlet      -l version -f -d "Show version info"
complete -c configlet -s t -l track-dir -d "Select a track directory"
complete -c configlet -s v -l verbosity -x -a "quiet normal detailed" -d "Verbose level"

# subcommands with no options
complete -c configlet -n "__fish_use_subcommand" -a lint -f -d "Check the track configuration for correctness"
complete -c configlet -n "__fish_use_subcommand" -a generate -f -d "Generate concept exercise introductions"

# info subcommand
complete -c configlet -n "__fish_use_subcommand" -a info -f -d "Track info"
complete -c configlet -n "__fish_seen_subcommand_from info" -s o -l offline -f -d "Do not update prob-specs cache"

# uuid subcommand
complete -c configlet -n "__fish_use_subcommand" -a uuid -f -d "Output a UUID"
complete -c configlet -n "__fish_seen_subcommand_from uuid" -s n -l num -f -d "How many UUIDs"

# fmt subcommand
complete -c configlet -n "__fish_use_subcommand" -a fmt -f -d "Format the exercise '.meta/config.json' files"
complete -c configlet -n "__fish_seen_subcommand_from fmt" -s u -l update -d "Write changes"
complete -c configlet -n "__fish_seen_subcommand_from fmt" -s y -l yes -d "Auto-confirm update"
complete -c configlet -n "__fish_seen_subcommand_from fmt" -s e -l exercise -d "exercise slug" \
  -x -a "(find ./exercises/{concept,practice} -maxdepth 1 -mindepth 1 -type d -printf '%P\n' | sort)"

# sync subcommand
complete -c configlet -n "__fish_use_subcommand" -a sync -d "Check or update Practice Exercise docs, metadata, and tests"
complete -c configlet -n "__fish_seen_subcommand_from sync" -s o -l offline -f -d "Do not update prob-specs cache"
complete -c configlet -n "__fish_seen_subcommand_from sync" -s u -l update -d "Write changes"
complete -c configlet -n "__fish_seen_subcommand_from sync" -s y -l yes -d "Auto-confirm update"
complete -c configlet -n "__fish_seen_subcommand_from sync"      -l docs -d "Sync docs only"
complete -c configlet -n "__fish_seen_subcommand_from sync"      -l filepaths -f -d 'Populate .meta/config.json "files" entry'
complete -c configlet -n "__fish_seen_subcommand_from sync"      -l metadata -d "Sync metadata only"
complete -c configlet -n "__fish_seen_subcommand_from sync"      -l tests -d "For auto-confirming" -x -a "choose include exclude"
complete -c configlet -n "__fish_seen_subcommand_from sync" -s e -l exercise -d "exercise slug" \
  -x -a "(find ./exercises/practice -maxdepth 1 -mindepth 1 -type d -printf '%P\n' | sort)"

@ee7 ee7 force-pushed the add-completion-subcommand branch from 12e3630 to 478df76 Compare August 4, 2022 14:51
@ee7 ee7 marked this pull request as ready for review August 4, 2022 14:53
@ee7 ee7 mentioned this pull request Aug 4, 2022
Copy link
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

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

LGTM. Seems to work well on my machine

ee7 added 5 commits August 6, 2022 10:15
Output on success:

    [Suite] completion
      [OK] bash
      [OK] fish
      [OK] powershell (produces an error)
      [OK] zsh (produces an error)
The previous commit adds a test that works locally, but not in the
GitHub Actions environment. There, the start of the output (`Error`) is
printed in red. So `startsWith` would have to use color codes.

Let's just use `contains`, which is what we do elsewhere in this file.
We already check the exit code.
@ee7 ee7 force-pushed the add-completion-subcommand branch from 1d55b9d to c41f790 Compare August 6, 2022 08:16
@ee7 ee7 merged commit d10dcd6 into exercism:main Aug 6, 2022
@ee7 ee7 deleted the add-completion-subcommand branch August 6, 2022 09:18
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.

completion: add configlet completion subcommand
2 participants