Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
weieigao committed Jul 5, 2018
2 parents 2d0189e + 3191317 commit 80f1572
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package plugin

import (
"fmt"
"strings"

"github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/models"
)

// PluginMetadata describes metadata of a plugin.
type PluginMetadata struct {
Name string // name of the plugin
Aliases []string // aliases of the plugin
Version VersionType // version of the plugin
MinCliVersion VersionType // minimal version of CLI required by the plugin
Namespaces []Namespace // list of namespaces provided by the plugin
Expand All @@ -23,6 +23,10 @@ type PluginMetadata struct {
SDKVersion VersionType
}

func (p PluginMetadata) NameAndAliases() []string {
return append([]string{p.Name}, p.Aliases...)
}

// VersionType describes the version info
type VersionType struct {
Major int // major version
Expand All @@ -45,42 +49,34 @@ func (v VersionType) String() string {
// Namespace also supports hierarchy. For example, namespace 'A' can have a sub
// namespace 'B'. And the full qualified name of namespace B is 'A B'.
type Namespace struct {
Name string // full qualified name of the namespace
Description string // description of the namespace
ParentName string // full qualified name of the parent namespace
Name string // base name
Aliases []string // aliases
Description string // description of the namespace
}

// ParentName returns the name of its parent namespace
func (n Namespace) ParentName() string {
i := strings.LastIndex(n.Name, " ")
if i < 0 {
return ""
}
return n.Name[:i]
func (n Namespace) NameAndAliases() []string {
return append([]string{n.Name}, n.Aliases...)
}

// Command describes the metadata of a plugin command
type Command struct {
Namespace string // full qualified name of the command's namespace
Name string // name of the command
Alias string // command alias, usually the command's short name
Description string // short description of the command
Usage string // usage detail to be displayed in command help
Flags []Flag // command options
Hidden bool // true to hide the command in help text
}

// FullName returns Command's fully-qualified name prefixed with namespace
func (c Command) FullName() string {
return strings.TrimSpace(strings.Join([]string{c.Namespace, c.Name}, " "))
Namespace string // full qualified name of the command's namespace
Name string // name of the command
Alias string // Deprecated: use Aliases instead.
Aliases []string // command aliases
Description string // short description of the command
Usage string // usage detail to be displayed in command help
Flags []Flag // command options
Hidden bool // true to hide the command in help text
}

// FullNames returns Commands's full-qualified names prefixed with namespace
func (c Command) FullNames() []string {
names := []string{c.FullName()}
if c.Alias != "" {
names = append(names, strings.TrimSpace(strings.Join([]string{c.Namespace, c.Alias}, " ")))
func (c Command) NameAndAliases() []string {
as := c.Aliases
if len(as) == 0 && c.Alias != "" {
as = []string{c.Alias}
}
return names
return append([]string{c.Name}, as...)
}

// Flag describes a command option
Expand Down

0 comments on commit 80f1572

Please sign in to comment.