vmware-tanzu / tanzu-cli

The Tanzu Core CLI project provides the core functionality of the Tanzu CLI. The CLI is based on a plugin architecture where CLI command functionality can be delivered through independently developed plugin binaries
Apache License 2.0
35 stars 22 forks source link

Respect command mapping for help from plugins #777

Closed marckhouzam closed 4 months ago

marckhouzam commented 4 months ago

What this PR does / why we need it

When remapping plugin commands, the tanzu help command on those remapped commands is not correct.

For example

# The trait commands is actually remapped from "space trait"
# Notice that we are getting the help from "space" instead of "trait"
$ tz help trait
Tanzu space lifecycle management

Usage:
  tanzu space [command]

Aliases:
  space, spaces, sp

Available Commands:
  create              Create a Space with specified configuration
  delete              Delete a space
[...]

# The deploy command is remapped from "resource deploy"
# Notice that we are getting the help from "resource" instead of "deploy"
$ tz help deploy
manage resources in a Kubernetes cluster

Usage:

Flags:
  -h, --help   help for resource

Which issue(s) this PR fixes

Fixes # N/A

Describe testing done for PR

After the PR:

$ tz help trait
Trait lifecycle management

Usage:
  tanzu trait [command]

Aliases:
  trait, traits, tr

Available Commands:
  create      Create a trait with specified configuration
  delete      Delete a trait
  generate    Generate a trait manifest with specified configuration.
  get         Get details from a trait.
  list        List the traits in the current workspace.

Flags:
  -h, --help   help for trait

Global Flags:
      --no-color       deactivate color, bold, animations, and emoji output
      --project name   name of the project to use when creating resources, or switching spaces (default is project name from current-context defined by Application Engine)

Use "tanzu trait [command] --help" for more information about a command.

$ tz help deploy
Deploy resources on the cluster

Usage:
  tanzu deploy [flags]

Flags:
      --diff                Show diff
      --from-build string   Set build output directory (format: /tmp/foo)
  -h, --help                help for deploy
      --only strings        Set files or directories to patch, ignoring tanzu.yml (format: file1.yml, dirname/) (can repeat)
      --patch               Patch resources
  -y, --yes                 Confirm all prompts with yes

Notice that the invocation form is respected:

# Calling "space trait" instead of "trait" is reflected in the help
$ tz help space trait
Trait lifecycle management

Usage:
  tanzu space trait [command]
[...]

# Aliases also work
$ tz help tr
Trait lifecycle management

Usage:
  tanzu trait [command]

Aliases:
  trait, traits, tr

[...]

$ tz help space tr
Trait lifecycle management

Usage:
  tanzu space trait [command]

Aliases:
  trait, traits, tr
[...]

Release note

Respect command mapping for the help command for plugins

Additional information

Special notes for your reviewer

marckhouzam commented 4 months ago

Nice catch, and fix! I suggest we add a test case or two to exercise the tanzu help functionality if possible.

I've added a couple of tests that fail before this change and pass after.