diff --git a/pkg/cli/plugin_cmd.go b/pkg/cli/plugin_cmd.go index 8e6e53dee..7cb07782e 100644 --- a/pkg/cli/plugin_cmd.go +++ b/pkg/cli/plugin_cmd.go @@ -56,7 +56,8 @@ func GetCommandMapForPlugin(p *PluginInfo) map[string]*cobra.Command { dstPath := pathFromHierarchy(cmdHierarchy) cmdMap[dstPath] = getCmdForPluginEx(p, cmdHierarchy[len(cmdHierarchy)-1], &mapEntry) if alternateLocation := alternateRemapLocation(p, dstPath); alternateLocation != "" { - cmdMap[alternateLocation] = cmdMap[dstPath] + mapEntry.DestinationCommandPath = alternateLocation + cmdMap[alternateLocation] = getCmdForPluginEx(p, cmdHierarchy[len(cmdHierarchy)-1], &mapEntry) } } } diff --git a/pkg/command/root_test.go b/pkg/command/root_test.go index 657aa257e..b20492d36 100644 --- a/pkg/command/root_test.go +++ b/pkg/command/root_test.go @@ -1825,7 +1825,7 @@ func TestCommandRemapping(t *testing.T) { expected: []string{"hello !!"}, }, { - test: "command-level: invocation details available when plugin command is mapped to xxtop level", + test: "command-level: invocation details available when plugin command is mapped to top level", pluginVariants: []fakePluginRemapAttributes{ { name: "dummy", @@ -1842,6 +1842,24 @@ func TestCommandRemapping(t *testing.T) { args: []string{"invoke-info", "arg1", "arg2"}, expected: []string{"args = (show-invoke-context arg1 arg2), context is ():(invoke-info):(show-invoke-context)"}, }, + { + test: "command-level: invocation details available when plugin command is mapped to top level and invoked via a target", + pluginVariants: []fakePluginRemapAttributes{ + { + name: "dummy", + target: configtypes.TargetK8s, + commandMap: []plugin.CommandMapEntry{ + plugin.CommandMapEntry{ + DestinationCommandPath: "invoke-info", + SourceCommandPath: "show-invoke-context", + Description: "Shows invocation details", + }, + }, + }, + }, + args: []string{"kubernetes", "invoke-info", "arg1", "arg2"}, + expected: []string{"args = (show-invoke-context arg1 arg2), context is (kubernetes):(invoke-info):(show-invoke-context)"}, + }, { test: "command-level: invocation details available when plugin command is mapped to deeper level", pluginVariants: []fakePluginRemapAttributes{