Adds support to a tree hierarchy of kubectl plugins
This commit is contained in:
@@ -16,7 +16,10 @@ limitations under the License.
|
||||
|
||||
package plugins
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Plugin is the representation of a CLI extension (plugin).
|
||||
type Plugin struct {
|
||||
@@ -28,11 +31,12 @@ type Plugin struct {
|
||||
// PluginDescription holds everything needed to register a
|
||||
// plugin as a command. Usually comes from a descriptor file.
|
||||
type Description struct {
|
||||
Name string `json:"name"`
|
||||
ShortDesc string `json:"shortDesc"`
|
||||
LongDesc string `json:"longDesc,omitempty"`
|
||||
Example string `json:"example,omitempty"`
|
||||
Command string `json:"command"`
|
||||
Name string `json:"name"`
|
||||
ShortDesc string `json:"shortDesc"`
|
||||
LongDesc string `json:"longDesc,omitempty"`
|
||||
Example string `json:"example,omitempty"`
|
||||
Command string `json:"command"`
|
||||
Tree []*Plugin `json:"tree,omitempty"`
|
||||
}
|
||||
|
||||
// PluginSource holds the location of a given plugin in the filesystem.
|
||||
@@ -41,12 +45,23 @@ type Source struct {
|
||||
DescriptorName string `json:"-"`
|
||||
}
|
||||
|
||||
var IncompleteError = fmt.Errorf("incomplete plugin descriptor: name, shortDesc and command fields are required")
|
||||
var (
|
||||
IncompleteError = fmt.Errorf("incomplete plugin descriptor: name, shortDesc and command fields are required")
|
||||
InvalidNameError = fmt.Errorf("plugin name can't contain spaces")
|
||||
)
|
||||
|
||||
func (p Plugin) Validate() error {
|
||||
if len(p.Name) == 0 || len(p.ShortDesc) == 0 || len(p.Command) == 0 {
|
||||
if len(p.Name) == 0 || len(p.ShortDesc) == 0 || (len(p.Command) == 0 && len(p.Tree) == 0) {
|
||||
return IncompleteError
|
||||
}
|
||||
if strings.Index(p.Name, " ") > -1 {
|
||||
return InvalidNameError
|
||||
}
|
||||
for _, child := range p.Tree {
|
||||
if err := child.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user