ajalt / clikt

Multiplatform command line interface parsing for Kotlin
https://ajalt.github.io/clikt/
Apache License 2.0
2.56k stars 123 forks source link

Bash completion script is broken if an `argument()` metavar contains spaces #563

Open joffrey-bion opened 2 weeks ago

joffrey-bion commented 2 weeks ago

I have a command like this, and for some reason someone decided to put spaces in the arguments metavar:

internal class RunCommand : AmperSubcommand(name = "run") {
    private val programArguments by argument(name = "program arguments").multiple()

   // ...
}

When sourcing the generated bash completion for this, I get the following error:

-bash: /home/jbion/amper-completion.bash: line 539: syntax error near unexpected token `arguments'
-bash: /home/jbion/amper-completion.bash: line 539: `    program arguments)'

Adding quotes around program arguments in the completion script solves the problem.

I guess there are 2 ways this could be solved:

  1. forbid spaces (and other chars that could mess up with bash) in the metavar name with an explicit doc and error
  2. quote the metavar name in the bash case