devops-rob / target-cli

A CLI tool to manage context profiles for HashiCorp tools
Apache License 2.0
32 stars 5 forks source link

Shell completion [Bash]: duplicate entries generated #23

Open yermulnik opened 10 months ago

yermulnik commented 10 months ago
> . <(target completion bash)

> target<tab><tab>
boundary
boundary    (Manage Boundary context profiles)
completion  (Generate the autocompletion script for the specified shell)
config
config      (Configure target CLI for shell sessions)
consul
consul      (Manage consul context profiles)
help        (Help about any command)
nomad
nomad       (Manage Nomad context profiles)
terraform
terraform   (Manage Terraform context profiles)
vault
vault       (Manage Vault context profiles)
version
version     (Show current installed version of target-cli)

> target confi<tab><tab>
config                                             config  (Configure target CLI for shell sessions)

> target terraform l<tab><tab>
list                                                    list  (list all context profiles for your chosen tool)

Looks like all the commands suffer from this "issue".

devops-rob commented 10 months ago

Thanks for raising this issue and i'm sorry about that. Can you confirm the steps you took to enable the shell completion @yermulnik

yermulnik commented 10 months ago

Can you confirm the steps you took to enable the shell completion

It's in the very first message. Let me show this explicitly:

# starting a new shell with `target-cli` completion not loaded
> which target
/home/linuxbrew/.linuxbrew/bin/target

> target vers<tab><tab> # doesn't complete
> . <(target completion bash)
> target vers<tab><tab>
version                                                  version  (Show current installed version of target-cli)
> target version

Obviously in real life the . <(target completion bash) step is automated by means of bash-completion and the ~/.bash_completion.d/target.completion file:

> cat ~/.bash_completion.d/target.completion
. <(target completion bash)
yermulnik commented 10 months ago
> bash --version | head -1
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
yermulnik commented 10 months ago

And in case if debug log helps

This if for target <tab><tab>:

========= starting completion logic ==========
cur is , words[*] is target , #words[@] is 2, cword is 1
Truncated words[*]: target ,
lastParam , lastChar
Adding extra empty parameter
Calling target __complete  ''
The completion directive is: 4
The completions are: boundary   Manage Boundary context profiles
completion      Generate the autocompletion script for the specified shell
config  Configure target CLI for shell sessions
consul  Manage consul context profiles
help    Help about any command
nomad   Manage Nomad context profiles
terraform       Manage Terraform context profiles
vault   Manage Vault context profiles
version Show current installed version of target-cli
vault
nomad
consul
boundary
terraform
config
version

Activating no file completion
__target_handle_completion_types: COMP_TYPE is 33
Original comp: boundary Manage Boundary context profiles
Final comp: boundary    (Manage Boundary context profiles)
Original comp: completion       Generate the autocompletion script for the specified shell
Final comp: completion  (Generate the autocompletion script for the specified shell)
Original comp: config   Configure target CLI for shell sessions
Final comp: config      (Configure target CLI for shell sessions)
Original comp: consul   Manage consul context profiles
Final comp: consul      (Manage consul context profiles)
Original comp: help     Help about any command
Final comp: help        (Help about any command)
Original comp: nomad    Manage Nomad context profiles
Final comp: nomad       (Manage Nomad context profiles)
Original comp: terraform        Manage Terraform context profiles
Final comp: terraform   (Manage Terraform context profiles)
Original comp: vault    Manage Vault context profiles
Final comp: vault       (Manage Vault context profiles)
Original comp: version  Show current installed version of target-cli
Final comp: version     (Show current installed version of target-cli)

This one is for target vers<tab><tab>:

========= starting completion logic ==========
cur is vers, words[*] is target vers, #words[@] is 2, cword is 1
Truncated words[*]: target vers,
lastParam vers, lastChar s
Calling target __complete vers
The completion directive is: 4
The completions are: version    Show current installed version of target-cli
version

Activating no file completion
__target_handle_completion_types: COMP_TYPE is 33
Original comp: version  Show current installed version of target-cli
Final comp: version  (Show current installed version of target-cli)