forked from redhat-developer/odo
/
describe.go
54 lines (45 loc) · 1.65 KB
/
describe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package component
import (
"github.com/redhat-developer/odo/pkg/component"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
appCmd "github.com/redhat-developer/odo/pkg/odo/cli/application"
projectCmd "github.com/redhat-developer/odo/pkg/odo/cli/project"
"github.com/spf13/cobra"
)
var describeCmd = &cobra.Command{
Use: "describe [component_name]",
Short: "Describe the given component",
Long: `Describe the given component.`,
Example: ` # Describe nodejs component,
odo describe nodejs
`,
Args: cobra.RangeArgs(0, 1),
Run: func(cmd *cobra.Command, args []string) {
context := genericclioptions.NewContext(cmd)
client := context.Client
applicationName := context.Application
// If no arguments have been passed, get the current component
// else, use the first argument and check to see if it exists
var componentName string
if len(args) == 0 {
componentName = context.Component()
} else {
componentName = context.Component(args[0])
}
componentDesc, err := component.GetComponentDesc(client, componentName, applicationName)
odoutil.LogErrorAndExit(err, "")
odoutil.PrintComponentInfo(componentName, componentDesc)
},
}
// NewCmdDescribe implements the describe odo command
func NewCmdDescribe() *cobra.Command {
// Add a defined annotation in order to appear in the help menu
describeCmd.Annotations = map[string]string{"command": "component"}
describeCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
//Adding `--project` flag
projectCmd.AddProjectFlag(describeCmd)
//Adding `--application` flag
appCmd.AddApplicationFlag(describeCmd)
return describeCmd
}