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

Bash completion error with multiple dashes in subcommands #61

Open
r-didato opened this issue Feb 27, 2023 · 0 comments
Open

Bash completion error with multiple dashes in subcommands #61

r-didato opened this issue Feb 27, 2023 · 0 comments

Comments

@r-didato
Copy link

Describe the bug

The bash completion script doesn't suggest short and long options when using a subcommand containing more than one dash.

To Reproduce

Create a simple node program

var dashdash = require('dashdash');

var specExtra='
local cmd_subcmds="my-test-subcommand"
local cmd_allsubcmds="my-test-subcommand"

local cmd__my_test_subcommand_shortopts="-f"
local cmd__my_test_subcommand_longopts="--file"
local cmd__my_test_subcommand_optargs=""
';

var code = dashdash.bashCompletionFromOptions({
    name: 'mycli',
    options: [],
    specExtra: specExtra
});

fs.writeFileSync( 'bashCompletionTest', code );

This generates a bash completion file 'bashCompletionTest', this file should include the following lines that define a 'my-test-subcommand' subcommand with options -f and --file

local cmd_subcmds="my-test-subcommand"
local cmd_allsubcmds="my-test-subcommand"

local cmd__my_test_subcommand_shortopts="-f"
local cmd__my_test_subcommand_longopts="--file"
local cmd__my_test_subcommand_optargs=""

Just source the file we just created with

source bashCompletionTest

Expected behavior

Tabbing on 'mycli my-test-subcommand -' i should see -f and --file as options, instead i don't see any possible completion

Additional context

I checked the logs and i found out that the completion script doesn't replace correctly all dashes and changes only the first one, so it searches for options of command my_test-subcommand (to be more precise checks variable cmd__my_test-subcommand_shortopts)

Possible fix

To fix just replace all instances of '-' instead of the first one only.

At line 196 of etc/dashdash.bash_completion.in :

- _dashdash_complete $(( $i + 1 )) "${context}__${arg/-/_}"
+ _dashdash_complete $(( $i + 1 )) "${context}__${arg//-/_}"
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

No branches or pull requests

1 participant