Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Bash shell completion becomes stale when installing/uninstalling plugins #3963

Closed
marckhouzam opened this issue Nov 21, 2022 · 0 comments · Fixed by #4001
Closed

Bash shell completion becomes stale when installing/uninstalling plugins #3963

marckhouzam opened this issue Nov 21, 2022 · 0 comments · Fixed by #4001
Labels
area/core-cli kind/bug PR/Issue related to a bug

Comments

@marckhouzam
Copy link
Contributor

Bug description

Although I have shell completion correctly working with the bash shell, once I install a new plugin, the shell completion does not include the new plugin. Also, when I remove a plugin, the bash shell completion continues to complete the plugin name as if it was still available.

The problem is that tanzu's bash completion uses a static script that hard-code the list of plugins at the time the script is generated. Every time a plugin is added or removed, the script would need to be re-generated and re-sourced by the user.
This does not happen to the other shells (zsh, fish, powershell) because they use a "dynamic" script that requests shell completions from the tanzu CLI itself at the time they are needed by the user.

Cobra provides such a dynamic solution for bash completion in its bash completion V2 solution: https://github.com/spf13/cobra/blob/main/shell_completions.md#bash-completion-v2

Affected product area (please put an X in all that apply)

  • ( ) APIs
  • ( ) Addons
  • (x) CLI
  • ( ) Docs
  • ( ) IAM
  • ( ) Installation
  • (x) Plugin
  • ( ) Security
  • ( ) Test and Release
  • (x) User Experience
  • ( ) Developer Experience

Expected behavior

The shell completion should always reflect the current available list of commands/plugins

Steps to reproduce the bug

$ bash

# Delete all plugins
bash-5.1$ tanzu plugin clean
✔  successfully cleaned up all plugins

# Setup shell completion
bash-5.1$ source <(tanzu completion bash)

# Notice that shell completion correctly does not suggest plugins yet
bash-5.1$ tanzu [tab][tab]
completion  config      context     help        init        plugin      update      version

bash-5.1$ tanzu plugin install login
ℹ  Installing plugin 'login:v0.28.0-dev'
✔  successfully installed 'login' plugin

# Notice shell completion still does not suggest the login plugin even though it should
bash-5.1$ tanzu l[tab][tab]
bash-5.1$ tanzu -h | grep login
    login                   Login to the platform

# I need to source the script again to get the new list of plugins
bash-5.1$ source <(tanzu completion bash)

# Notice that the login plugin is now suggested
bash-5.1$ tanzu [tab][tab]
completion  config      context     help        init        login       plugin      update      version

# Delete all plugins
bash-5.1$ tanzu plugin clean
✔  successfully cleaned up all plugins

# Notice the login plugin is still suggested when it should not
bash-5.1$ tanzu [tab][tab]
completion  config      context     help        init        login       plugin      update      version

Version (include the SHA if the version is not obvious)

Today's main branch: 64cda44

Environment where the bug was observed (cloud, OS, etc)

Locally

Relevant Debug Output (Logs, manifests, etc)

@marckhouzam marckhouzam added kind/bug PR/Issue related to a bug area/core-cli labels Nov 21, 2022
marckhouzam added a commit to marckhouzam/tanzu-framework that referenced this issue Nov 24, 2022
Fix vmware-tanzu#3963

Cobra's bash completion V2 is the version now maintained by Cobra.
See https://github.com/spf13/cobra/blob/main/shell_completions.md#bash-completion-v2

This new version comes with extra features compared to the original bash
completion logic, such as:
- Supports completion descriptions (like the other shells)
- Small bash completion script (325 lines versus 1342 lines for tanzu)
- Streamlined user experience thanks to a completion behavior aligned
  with the other shells (for example, it does not suggest the = form for
  flag completion)

This commit also enables completion descriptions for bash which is
available with Cobra's bash completion v2.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
marckhouzam added a commit to marckhouzam/tanzu-framework that referenced this issue Nov 24, 2022
Fix vmware-tanzu#3963

Cobra's bash completion V2 is the version now maintained by Cobra.
See https://github.com/spf13/cobra/blob/main/shell_completions.md#bash-completion-v2

This new version comes with extra features compared to the original bash
completion logic, such as:
- Supports completion descriptions (like the other shells)
- Small bash completion script (325 lines versus 1342 lines for tanzu)
- Streamlined user experience thanks to a completion behavior aligned
  with the other shells (for example, it does not suggest the = form for
  flag completion)

This commit also enables completion descriptions for bash which is
available with Cobra's bash completion v2.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
randomvariable pushed a commit that referenced this issue Nov 25, 2022
Fix #3963

Cobra's bash completion V2 is the version now maintained by Cobra.
See https://github.com/spf13/cobra/blob/main/shell_completions.md#bash-completion-v2

This new version comes with extra features compared to the original bash
completion logic, such as:
- Supports completion descriptions (like the other shells)
- Small bash completion script (325 lines versus 1342 lines for tanzu)
- Streamlined user experience thanks to a completion behavior aligned
  with the other shells (for example, it does not suggest the = form for
  flag completion)

This commit also enables completion descriptions for bash which is
available with Cobra's bash completion v2.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/core-cli kind/bug PR/Issue related to a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant