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

Use proper help format for "completion" #613

Merged
merged 1 commit into from
Dec 15, 2023

Conversation

marckhouzam
Copy link
Contributor

What this PR does / why we need it

The completion and generate-all-docs commands' help were using the root command's help format by mistake. This PR fixes that.

Also, this PR improves the output of the list of shells in the help output of the completion command.

Which issue(s) this PR fixes

Fixes # N/A

Describe testing done for PR

Before this commit, notice below

  1. the invalid use of [command]
  2. the invalid use of Available command groups
  3. the poor formatting of the list [bash zsh fish powershell]
$ ~/bin/tanzu.v1.0.0 completion -h

Output shell completion code for the specified shell [bash zsh fish powershell].

The shell completion code must be evaluated to provide completion. See Examples
for how to perform this for your given shell.

Note for bash users: make sure the bash-completions package has been installed.

Usage:
  tanzu completion [command]

Examples:

# Bash instructions:

  ## Load only for current session:
  source <(tanzu completion bash)

  ## Load for all new sessions:
  tanzu completion bash >  $HOME/.config/tanzu/completion.bash.inc
  printf "\n# Tanzu shell completion\nsource '$HOME/.config/tanzu/completion.bash.inc'\n" >> $HOME/.bash_profile

  ## NOTE: the bash-completion package must be installed.

# Zsh instructions:

  ## Load only for current session:
  autoload -U compinit; compinit
  source <(tanzu completion zsh)
  compdef _tanzu tanzu

  ## Load for all new sessions:
  echo "autoload -U compinit; compinit" >> ~/.zshrc
  tanzu completion zsh > "${fpath[1]}/_tanzu"

# Fish instructions:

  ## Load only for current session:
  tanzu completion fish | source

  ## Load for all new sessions:
  tanzu completion fish > ~/.config/fish/completions/tanzu.fish

# Powershell instructions:

  ## Load only for current session:
  tanzu completion powershell | Out-String | Invoke-Expression

  ## Load for all new sessions:
  Add the output of the above command to your powershell profile.

Available command groups:


Flags:
  -h, --help   help for completion

Use "tanzu completion [command] --help" for more information about a command.
$ ~/bin/tanzu.v1.0.0 generate-all-docs -h
Generate Cobra CLI docs for all plugins installed

Usage:
  tanzu generate-all-docs [command]

Available command groups:


Flags:
  -d, --docs-dir string   destination for docs output (default "docs/cli/commands")
  -h, --help              help for generate-all-docs

Use "tanzu generate-all-docs [command] --help" for more information about a command.

After this commit, notice the help format

  1. does not use [command] anymore
  2. no longer uses Available command groups
  3. the better formatting of the lists [bash zsh fish powershell]
$ tz completion -h
Output shell completion code for the specified shell (bash, zsh, fish, powershell).

The shell completion code must be evaluated to provide completion. See Examples
for how to perform this for your given shell.

Note for bash users: make sure the bash-completions package has been installed.

Usage:
tanzu completion [bash|zsh|fish|powershell]

Examples:

# Bash instructions:

  ## Load only for current session:
  source <(tanzu completion bash)

  ## Load for all new sessions:
  tanzu completion bash > $HOME/.config/tanzu/completion.bash.inc
  printf "\n# Tanzu shell completion\nsource '$HOME/.config/tanzu/completion.bash.inc'\n" >> $HOME/.bashrc

  ## NOTE: the bash-completion OS package must also be installed.

  ## If you invoke the 'tanzu' command using a different name or an alias such as,
  ## for example, 'tz', you must also include the following in your $HOME/.bashrc
  complete -o default -F __start_tanzu tz

# Zsh instructions:

  ## Load only for current session:
  autoload -U compinit; compinit
  source <(tanzu completion zsh)

  ## Load for all new sessions:
  echo "autoload -U compinit; compinit" >> $HOME/.zshrc
  tanzu completion zsh > "${fpath[1]}/_tanzu"

  ## Aliases are handled automatically, but if you have renamed the actual 'tanzu' binary to,
  ## for example, 'tz', you must also include the following in your $HOME/.zshrc
  compdef _tanzu tz

# Fish instructions:

  ## Load only for current session:
  tanzu completion fish | source

  ## Load for all new sessions:
  tanzu completion fish > $HOME/.config/fish/completions/tanzu.fish

  ## Aliases are handled automatically, but if you have renamed the actual 'tanzu' binary to,
  ## for example, 'tz', you must also include the following in your $HOME/.config/fish/config.fish
  complete --command tz --wraps tanzu

# Powershell instructions:

  ## Load only for current session:
  tanzu completion powershell | Out-String | Invoke-Expression

  ## Load for all new sessions:
  printf "\n# Tanzu shell completion\ntanzu completion powershell | Out-String | Invoke-Expression" >> $PROFILE

  ## If you invoke the 'tanzu' command using a different name or an alias such as,
  ## for example, 'tz', you must also include the following in your powershell $PROFILE.
  Register-ArgumentCompleter -CommandName 'tz' -ScriptBlock ${__tanzuCompleterBlock}

Flags:
  -h, --help   help for completion

$ tz completion
[x] : shell not specified, choose one of: bash, zsh, fish, powershell

$ tz generate-all-docs -h
Generate Cobra CLI docs for all plugins installed

Usage:
tanzu generate-all-docs [flags]

Flags:
  -d, --docs-dir string   destination for docs output (default "docs/cli/commands")
  -h, --help              help for generate-all-docs

Release note

Use proper help format for "tanzu completion"

Additional information

Special notes for your reviewer

@marckhouzam marckhouzam requested a review from a team as a code owner December 10, 2023 20:38
@marckhouzam marckhouzam added this to the v1.2.0 milestone Dec 11, 2023
@marckhouzam marckhouzam added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process label Dec 11, 2023
The "completion" and "generate-all-docs" commands' help were using the
root command's help format by mistake. This commit fixes that.

Also, this commit improves the output of the list of shells in the help
output of the "completion" command.

Signed-off-by: Marc Khouzam <marc.khouzam@broadcom.com>
Copy link
Contributor

@vuil vuil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like it! Thanks for the cleanup. lgtm

@marckhouzam marckhouzam merged commit e879460 into vmware-tanzu:main Dec 15, 2023
7 checks passed
@marckhouzam marckhouzam deleted the fix/commandHelp branch December 15, 2023 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-not-required kind/cleanup Categorizes issue or PR as related to cleaning up code, process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants