diff --git a/plugin/info_test.go b/plugin/info_test.go index c1cbce34..9e6aa4f9 100644 --- a/plugin/info_test.go +++ b/plugin/info_test.go @@ -46,9 +46,11 @@ func TestInfo(t *testing.T) { Hidden: false, SupportedContextType: []types.ContextType{types.ContextTypeTanzu}, CommandMap: []CommandMapEntry{ - CommandMapEntry{ + { SourceCommandPath: "subber", DestinationCommandPath: "subber", + Overrides: "somecommand", + RequiredContextType: []types.ContextType{types.ContextTypeTanzu}, }, }, } @@ -91,8 +93,11 @@ func TestInfo(t *testing.T) { assert.Equal(expectedInfo.DocURL, gotInfo.DocURL) assert.Equal(expectedInfo.Hidden, gotInfo.Hidden) assert.Equal(expectedInfo.SupportedContextType, gotInfo.SupportedContextType) + assert.Equal("somecommand", gotInfo.CommandMap[0].Overrides) + assert.Equal([]types.ContextType{types.ContextTypeTanzu}, gotInfo.CommandMap[0].RequiredContextType) assert.Equal(subCmd.Aliases, gotInfo.CommandMap[0].Aliases) assert.Equal(subCmd.Short, gotInfo.CommandMap[0].Description) + assert.Equal(expectedInfo.BinaryArch, gotInfo.BinaryArch) assert.Empty(gotInfo.PluginRuntimeVersion, "Should be empty since unit tests doesn't have the self (tanzu-plugin-runtime) module dependency") } diff --git a/plugin/types.go b/plugin/types.go index 44e42dc6..94d9cfa7 100644 --- a/plugin/types.go +++ b/plugin/types.go @@ -66,8 +66,8 @@ type CommandMapEntry struct { DestinationCommandPath string `json:"dstPath" yaml:"dstPath"` // By default, the command previously situated at the // DestinationCommandPath of the Tanzu CLI, if one exist, will be the one - // overridden by this entry. If this mapping attempt is intended to - // override another part of the Tanzu CLI command tree, the override path should be used. + // overridden by this entry. If this mapping attempt is intended to override + // another part of the Tanzu CLI command tree, the override path should be used. // Specified as a space-delimited path relative to the Tanzu CLI command tree. Overrides string `json:"overrides" yaml:"overrides"` // Required when remapping a subcommand of this plugin outside of the @@ -83,6 +83,10 @@ type CommandMapEntry struct { // sense that if unset, the aliases of the actual Command at the // SourceCommandPath will be used. Aliases []string `json:"aliases,omitempty" yaml:"aliases,omitempty"` + // RequiredContextType specifies one or more ContextType's that has to be active in order for this + // mapping to take effect. If unset, this entry's mapping will apply regardless of state of active + // contexts. + RequiredContextType []types.ContextType `json:"requiredContextType,omitempty" yaml:"requiredContextType,omitempty"` } // PluginDescriptor describes a plugin binary.