You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we generate the completion script for zsh, with a option with an alias, the completion shown looks incorrect.
That's because the description of key from alias is missing in the generated completion script for zsh.
-- values --
--bar -- Bar option
--foo -- Foo option
--help -- Show help
--version -- Show version number
-B -F --
# If you don't enable zsh-completion, you need to enable it first.# Clone and configure repository
$ git clone git@github.com:tasshi-playground/repro-yargs-generate-broken-completion-with-alias.git
$ cd repro-yargs-generate-broken-completion-with-alias
$ npm ci
$ npm run build
$ ./cli.js completion > /path/to/your/fpath/_cli.js
# Reload the shell
In the repository, I specified the options and aliases as follows.
The output when I strike the TAB should be the following.
./cli.js - #Strike TAB
-- values --
--bar -B -- Bar option
--foo -F -- Foo option
--help -- Show help
--version -- Show version number
Actual Behavior
The actual output is the following.
The aliases (-B and -F) are aligned to same line with no descriptions.
./cli.js - #Strike TAB
-- values --
--bar -- Bar option
--foo -- Foo option
--help -- Show help
--version -- Show version number
-B -F --
Cause
When I request a completion with striking the TAB key, completion function calls the original file with --get-yargs-completions option.
It is specified in completion script as follows.
If two candidates have the same description, _describe collects them together on the same row and ensures that descriptions are aligned in neatly in columns.
So if we want to align the option and its alias, we have to add the description of option to the alias as follows.
$ node ./lib/index.js --get-yargs-completions -
--version:Show version number
--foo:Foo option
-F:Foo option
--bar:Bar option
-B:Bar option
--help:Show help
The text was updated successfully, but these errors were encountered:
Hi there, and thanks for the great package.
I encountered following unexpected behavior.
Environment
Summary
When we generate the completion script for zsh, with a option with an alias, the completion shown looks incorrect.
That's because the description of key from alias is missing in the generated completion script for zsh.
-- values -- --bar -- Bar option --foo -- Foo option --help -- Show help --version -- Show version number -B -F --
Reproduction
I created the minimum reproduction in https://github.com/tasshi-playground/repro-yargs-generate-broken-completion-with-alias .
In the repository, I specified the options and aliases as follows.
Expected Behavior
The output when I strike the TAB should be the following.
Actual Behavior
The actual output is the following.
The aliases (
-B
and-F
) are aligned to same line with no descriptions.Cause
When I request a completion with striking the TAB key, completion function calls the original file with
--get-yargs-completions
option.It is specified in completion script as follows.
However, the output of
--get-yargs-completions
is incorrect.With current version of yargs, the output is the following.
$ node ./lib/index.js --get-yargs-completions - --version:Show version number --foo:Foo option -F: --bar:Bar option -B: --help:Show help
The key
-F
and-B
are specified without description.According to the document of zsh-completion, the two keys have the same description are collected together.
https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org#writing-simple-completion-functions-using-_describe
So if we want to align the option and its alias, we have to add the description of option to the alias as follows.
$ node ./lib/index.js --get-yargs-completions - --version:Show version number --foo:Foo option -F:Foo option --bar:Bar option -B:Bar option --help:Show help
The text was updated successfully, but these errors were encountered: