Skip to content

Conversation

@vuil
Copy link
Contributor

@vuil vuil commented Apr 16, 2024

What this PR does / why we need it

Replaces InvokedAs field in the PluginDescriptor with a list of CommandMapEntry's that can provide additional mapping details. In particular it can specify a destination command path of the Tanzu CLI to map to a specific non root command path in the plugin.

Adds support for capturing the invocation "context" by consuming environment variables that are expected to be set by the Tanzu CLI when invoking a command that is being mapped.

Information in this context allows the plugin to construct proper Help information, and learn if the its command being invoked is done via a command-level mapping or not.

Updates the usage to provides better output when help is invoked on a command-level mapping.

Some additional handling added to propagate aliases and description of a mapped subcommand.

    The aliases and description of a remapped subcommand CommandMapEntry
    should default to the Aliases and Short values of the Command in the
    plugin. Hence, the 'info' command will interrogate the plugin command
    tree for these values unless they are already explicitly specified in
    the CommandMapEntry.

Which issue(s) this PR fixes

Fixes #

Describe testing done for PR

  • Updated unit tests
  • Build sample plugins with command-level map and verified that the command's Aliases and Short description are propagated into the elevate Tanzu CLI commands.

Release note

Extend plugin mapping to command-level remapping. Introduce CommandMapEntry which replaces InvokedAs in PluginDescriptor.

Additional information

Special notes for your reviewer

@vuil vuil requested a review from a team as a code owner April 16, 2024 23:56
@vuil vuil changed the title Remap commandmap autoaliasdesc Autopopulate aliases and description of command-level map entries Apr 16, 2024
@vuil vuil changed the title Autopopulate aliases and description of command-level map entries WIP: Autopopulate aliases and description of command-level map entries Apr 16, 2024
@vuil vuil changed the title WIP: Autopopulate aliases and description of command-level map entries Autopopulate aliases and description of command-level map entries Apr 17, 2024
@vuil vuil changed the title Autopopulate aliases and description of command-level map entries Extend plugin mapping to command-level remapping Apr 17, 2024
Copy link
Contributor

@anujc25 anujc25 left a comment

Choose a reason for hiding this comment

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

Looks good 👍 . Just a few really minor comments.

@vuil vuil force-pushed the remap_commandmap_autoaliasdesc branch from ee0eb15 to 34eeb73 Compare April 19, 2024 15:42
Copy link
Contributor

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

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

Very nice. I like the clear way for a plugin to indicate any mapping. I also like that there can be multiple mappings and from sub-commands. Very powerful.

We'll need some release notes for this nice change.

This is pretty complex stuff to think about so I'm not quite done but here are minor comments to start.

return cmd.UseLine()
}

// TODO(vuil) look into still incorporating relevant parts of UseLine into output
Copy link
Contributor

Choose a reason for hiding this comment

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

note so we don't forget this as a follow-up

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed in #180

Copy link
Contributor

Choose a reason for hiding this comment

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

The aliases need some tweaks in the help. Specifically, if a plugin sub-command is mapped to a different name. For example, I mapped tanzu builder cli to tanzu mycli but then the alias is incorrect:

$ tz mycli -h
Build CLIs

Usage:
  tanzu mycli
  tanzu kubernetes mycli

  tanzu mycli [command]
  tanzu kubernetes mycli [command]

Aliases:
  cli, c
[...]

$ tz cli -h
[x] : unknown command "cli" for "tanzu"

Did you mean this?
	mycli

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, the issue is with still assuming the name of the plugin is always a valid alias entry (the first item int the alias list), which is no longer true for a mapped command. I will address it in a followup.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed in #180

@vuil vuil force-pushed the remap_commandmap_autoaliasdesc branch from 34eeb73 to 63e97b6 Compare April 19, 2024 19:52
Copy link
Contributor

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

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

Once the missing quote x2 is fixed (see comments) and that CI passes, this LGTM.

Nice job @vuil, this is some powerful stuff!

@vuil vuil force-pushed the remap_commandmap_autoaliasdesc branch from 63e97b6 to da4a99a Compare April 19, 2024 21:05
vuil added 4 commits April 19, 2024 14:11
Replaces InvokedAs field in the PluginDescriptor with a list of
CommandMapEntry's that can provide additional mapping details. In
particular it can specify a destination command path of the
Tanzu CLI to map to a specific non root command path in the plugin.

Adds support for capturing the invocation "context" by consuming
environment variables that are expected to be set by the Tanzu CLI.

Information in this context allows the plugin to construct proper Help
information, and learn if the its command being invoked is done via a
command-level mapping or not.

Updates the usage to provides better output when help is invoked on a
command-level mapping.
The aliases and description of a remapped subcommand CommandMapEntry
should default to the Aliases and Short values of the Command in the
plugin. Hence, the 'info' command will interrogate the plugin command
tree for these values unless they are already explicitly specified in
the CommandMapEntry.
- and some typos, linter warnings

Signed-off-by: Vui Lam <[email protected]>
@vuil vuil force-pushed the remap_commandmap_autoaliasdesc branch from da4a99a to c8b12e5 Compare April 19, 2024 21:11
@vuil vuil merged commit 8822322 into vmware-tanzu:main Apr 19, 2024
@marckhouzam marckhouzam added this to the v1.3.0 milestone Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants