-
Notifications
You must be signed in to change notification settings - Fork 787
/
get.go
140 lines (122 loc) · 3.95 KB
/
get.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package cmd
import (
"encoding/json"
"fmt"
"io"
"github.com/spf13/cobra"
"gopkg.in/AlecAivazis/survey.v1/terminal"
"github.com/ghodss/yaml"
"github.com/jenkins-x/jx/pkg/jx/cmd/templates"
"github.com/jenkins-x/jx/pkg/util"
)
// GetOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
// referencing the cmd.Flags()
type GetOptions struct {
CommonOptions
Output string
}
var (
get_long = templates.LongDesc(`
Display one or more resources.
` + valid_resources + `
`)
get_example = templates.Examples(`
# List all pipeines
jx get pipeline
# List all URLs for services in the current namespace
jx get url
`)
)
// NewCmdGet creates a command object for the generic "get" action, which
// retrieves one or more resources from a server.
func NewCmdGet(f Factory, in terminal.FileReader, out terminal.FileWriter, errOut io.Writer) *cobra.Command {
options := &GetOptions{
CommonOptions: CommonOptions{
Factory: f,
In: in,
Out: out,
Err: errOut,
},
}
cmd := &cobra.Command{
Use: "get TYPE [flags]",
Short: "Display one or more resources",
Long: get_long,
Example: get_example,
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
CheckErr(err)
},
SuggestFor: []string{"list", "ps"},
}
cmd.AddCommand(NewCmdGetActivity(f, in, out, errOut))
cmd.AddCommand(NewCmdGetAddon(f, in, out, errOut))
cmd.AddCommand(NewCmdGetApplications(f, in, out, errOut))
cmd.AddCommand(NewCmdGetAWSInfo(f, in, out, errOut))
cmd.AddCommand(NewCmdGetBranchPattern(f, in, out, errOut))
cmd.AddCommand(NewCmdGetBuild(f, in, out, errOut))
cmd.AddCommand(NewCmdGetBuildPack(f, in, out, errOut))
cmd.AddCommand(NewCmdGetChat(f, in, out, errOut))
cmd.AddCommand(NewCmdGetConfig(f, in, out, errOut))
cmd.AddCommand(NewCmdGetCVE(f, in, out, errOut))
cmd.AddCommand(NewCmdGetDevPod(f, in, out, errOut))
cmd.AddCommand(NewCmdGetEks(f, in, out, errOut))
cmd.AddCommand(NewCmdGetEnv(f, in, out, errOut))
cmd.AddCommand(NewCmdGetGit(f, in, out, errOut))
cmd.AddCommand(NewCmdGetHelmBin(f, in, out, errOut))
cmd.AddCommand(NewCmdGetIssue(f, in, out, errOut))
cmd.AddCommand(NewCmdGetIssues(f, in, out, errOut))
cmd.AddCommand(NewCmdGetLimits(f, in, out, errOut))
cmd.AddCommand(NewCmdGetPipeline(f, in, out, errOut))
cmd.AddCommand(NewCmdGetPostPreviewJob(f, in, out, errOut))
cmd.AddCommand(NewCmdGetPreview(f, in, out, errOut))
cmd.AddCommand(NewCmdGetQuickstartLocation(f, in, out, errOut))
cmd.AddCommand(NewCmdGetRelease(f, in, out, errOut))
cmd.AddCommand(NewCmdGetTeam(f, in, out, errOut))
cmd.AddCommand(NewCmdGetTeamRole(f, in, out, errOut))
cmd.AddCommand(NewCmdGetToken(f, in, out, errOut))
cmd.AddCommand(NewCmdGetTracker(f, in, out, errOut))
cmd.AddCommand(NewCmdGetURL(f, in, out, errOut))
cmd.AddCommand(NewCmdGetUser(f, in, out, errOut))
cmd.AddCommand(NewCmdGetWorkflow(f, in, out, errOut))
return cmd
}
// Run implements this command
func (o *GetOptions) Run() error {
return o.Cmd.Help()
}
// outputEmptyListWarning outputs a warning indicating that no items are available to display
func outputEmptyListWarning(out io.Writer) error {
_, err := fmt.Fprintf(out, "%s\n", "No resources found.")
return err
}
func (o *GetOptions) addGetFlags(cmd *cobra.Command) {
o.Cmd = cmd
cmd.Flags().StringVarP(&o.Output, "output", "o", "", "The output format such as 'yaml'")
}
// renderResult renders the result in a given output format
func (o *GetOptions) renderResult(value interface{}, format string) error {
switch format {
case "json":
data, err := json.Marshal(value)
if err != nil {
return err
}
_, e := o.Out.Write(data)
return e
case "yaml":
data, err := yaml.Marshal(value)
if err != nil {
return err
}
_, e := o.Out.Write(data)
return e
default:
return fmt.Errorf("Unsupported output format: %s", format)
}
}
func formatInt32(n int32) string {
return util.Int32ToA(n)
}