-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add support for command-level remapping #736
Add support for command-level remapping #736
Conversation
db23641
to
680de4d
Compare
379a474
to
50c02cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things that impact the help text
// Information about if command invocation is via a mapped command | ||
numParts := len(dstHierarchy) | ||
if numParts > 0 { | ||
env["TANZU_CLI_INVOKED_COMMAND"] = dstHierarchy[numParts-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tried to figure out the problem but this does not work if I'm invoking a sub-command of a mapped command.
For example, I have mapped tanzu builder cli
to tanzu cli
. If I run tanzu cli -h
things are good but not if I run tanzu cli add-plugin -h
:
$ tz cli add-plugin -h
Add a plugin to a repository
Usage:
tanzu cli
I tested and the variables are:
TANZU_CLI_INVOKED_GROUP:
TANZU_CLI_INVOKED_COMMAND: cli
TANZU_CLI_COMMAND_MAPPED_FROM: cli
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an issue with the usage generation. I will address it in a followup.
2163bb6
to
38437b3
Compare
Will update once the runtime changes are merged
This is done via processing any CommandMapEntry's specified the plugin's 'info' output The CommandMapEntry enables mapping of the plugin's root command or one of its sub-command to another location in the CLI's command tree. Also: enables the override of an existing plugin with the Overrides field of the CommandMapEntry. It is uncommon for this to be needed; it is useful when deploying a plugin that needs to explicitly remove certain commands from the CLI even though the plugin itself does not provide commands of the same names. For any command created via the commandMap, details about the invocation of said command be communicated to the plugin binary via the following environment variables: TANZU_CLI_INVOKED_GROUP: a space-delimited portion of the Tanzu CLI command invocation between the CLI binary and the command name itself. Empty when invoking a top-level command. e.g. "tanzu apply" TANZU_CLI_INVOKED_COMMAND: the name of the command in a Tanzu CLI command invocation TANZU_CLI_COMMAND_MAPPED_FROM: a space-delimited path relative to the plugin's root command of the command being invoked. The value is empty unless the CLI command invoked is mapped to a non-root command of the plugin. Note: The complete CLI command invocation can thus be reconstructed with tanzu_cli_binary_name "$TANZU_CLI_INVOKED_GROUP" "$TANZU_CLI_INVOKED_COMMAND" args* Plugins employing any form of command mapping are expected to make use of these values to adjust any command invocation references in their commands' outputs (e.g. help, examples)
38437b3
to
d2756a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. This is really great. 🚀
Let's try to address any critical pending comments as a follow-up.
What this PR does / why we need it
Notes to documenters:
Much of the information in this PR and additional Markdown changes are relevant for plugin developers, and should have little relevance to user-facing documentation.
Which issue(s) this PR fixes
Fixes #
Describe testing done for PR
See unit tests added.
In addition, built and installed a sample plugin modified with additional command and command map.
Baseline
Use a sample plugin with some trivial commands in this branch as baseline:
https://github.com/vuil/tanzu-cli/blob/sample-plugin-with-remap/test/sample-plugin/cmd/plugin/sample-plugin/main.go
Running CLI when sample plugin is installed:
Test behavior of CLI by reinstalling above plugin built with the following command maping customizations:
1. elevate command
2.plugin level mapping to second level of CLI command tree
3. Lone command elevated
4. Plugin level remap with overrides
5. Command level aliases and autocomplete
Release note
Additional information
Special notes for your reviewer
Testing with a plugin with mapping configuration such as the sample plugin requires that the built plugin be installed using a Tanzu CLI updated with the new plugin-runtime updates (under review in vmware-tanzu/tanzu-plugin-runtime#176)