Skip to content

Conversation

@kemelzaidan
Copy link
Contributor

Add completion for the default CLI tool for the Elm language which was lacking and neither provided for the tool authors. The completion code was written by myself.

Copy link
Contributor

@EmilyGraceSeville7cf EmilyGraceSeville7cf left a comment

Choose a reason for hiding this comment

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

Please respond to my comments, I try to do my best while reviewing the code. 😄

@@ -0,0 +1,24 @@
set -l commands repl init reactor make install bump diff publish

complete -c elm -f
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I would recommend putting elm in the variable like set -l command elm. However, till the command name is short and not gonna change then this solution may be pretty fine. 😄

Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't do that, this completion file will only ever work for elm.

My position on that idiom is that it's fake flexibility. You're never gonna change that one line to make it magically work for something else - the most common case is something like python/python2/python3, where you can use complete --wraps to reuse one completion script.

Or the tool renames itself entirely, and you just rename the file and do s/-c elm/-c banana/ on it.

So the variable gives you one additional line and a lot of $command everywhere for no real benefit.

# repl completions
complete -c elm -n "not __fish_seen_subcommand_from $commands" -a repl -d 'Open up an interactive programming session'
complete -c elm -n "__fish_seen_subcommand_from repl" -l no-colors -d 'Turn off the colors in REPL'
complete -c elm -n "__fish_seen_subcommand_from repl" -l interpreter= -d 'Path to an alternative JS interpreter'
Copy link
Contributor

@EmilyGraceSeville7cf EmilyGraceSeville7cf Oct 3, 2024

Choose a reason for hiding this comment

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

-l interpreter= for me looks a little bit suspicious, if you wanna an option to be assignable via = sign then don't add -r flag to complete.

# repl completions
complete -c elm -n "not __fish_seen_subcommand_from $commands" -a repl -d 'Open up an interactive programming session'
complete -c elm -n "__fish_seen_subcommand_from repl" -l no-colors -d 'Turn off the colors in REPL'
complete -c elm -n "__fish_seen_subcommand_from repl" -l interpreter= -d 'Path to an alternative JS interpreter'
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather put "__fish_seen_subcommand_from repl" in a some variable like so: set -l repl_condition "__fish_seen_subcommand_from repl".

complete -c elm -n "not __fish_seen_subcommand_from $commands" -a diff -d 'See what changed in a package between different versions'
complete -c elm -n "not __fish_seen_subcommand_from $commands" -a publish -d 'Publishes your package on package.elm-lang.org so anyone in the community can use it'

complete -c elm -l help -d "Show a more detailed description"
Copy link
Contributor

Choose a reason for hiding this comment

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

From my personal experience, I suggest moving -h|--help and -v|--version options always to the top. The point being that user should always be able to quickly understand how to get some help (although the mentioned flags are common, however, sometimes they vary a little bit).

@zanchey zanchey merged commit df6bd36 into fish-shell:master Feb 11, 2025
zanchey added a commit that referenced this pull request Feb 11, 2025
elm's argument parser copes just fine without them

Review comment from
#10759 (comment)
@zanchey zanchey self-assigned this Feb 11, 2025
@zanchey zanchey added this to the fish 4.0-final milestone Feb 11, 2025
@zanchey
Copy link
Member

zanchey commented Feb 11, 2025

Cherry-picked into 4.0 as 7ea368b with fixup suggested by @EmilyGraceSeville7cf as 1b6e107

zanchey added a commit that referenced this pull request Feb 11, 2025
elm's argument parser copes just fine without them

Review comment from
#10759 (comment)

(cherry picked from commit 2849cd1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants