Skip to content

Commit

Permalink
Add per-mapping required context type
Browse files Browse the repository at this point in the history
Signed-off-by: Vui Lam <[email protected]>
  • Loading branch information
vuil committed Jun 13, 2024
1 parent 30ec668 commit db69f8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion plugin/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
},
}
Expand Down Expand Up @@ -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")
}
8 changes: 6 additions & 2 deletions plugin/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit db69f8e

Please sign in to comment.