-
Notifications
You must be signed in to change notification settings - Fork 786
/
get.go
141 lines (123 loc) · 3.86 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
141
package cmd
import (
"encoding/json"
"fmt"
"io"
"github.com/spf13/cobra"
"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 pipelines
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(commonOpts *CommonOptions) *cobra.Command {
options := &GetOptions{
CommonOptions: commonOpts,
}
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(commonOpts))
cmd.AddCommand(NewCmdGetAddon(commonOpts))
cmd.AddCommand(NewCmdGetApps(commonOpts))
cmd.AddCommand(NewCmdGetApplications(commonOpts))
cmd.AddCommand(NewCmdGetAWSInfo(commonOpts))
cmd.AddCommand(NewCmdGetBranchPattern(commonOpts))
cmd.AddCommand(NewCmdGetBuild(commonOpts))
cmd.AddCommand(NewCmdGetBuildPack(commonOpts))
cmd.AddCommand(NewCmdGetChat(commonOpts))
cmd.AddCommand(NewCmdGetConfig(commonOpts))
cmd.AddCommand(NewCmdGetCVE(commonOpts))
cmd.AddCommand(NewCmdGetDevPod(commonOpts))
cmd.AddCommand(NewCmdGetEks(commonOpts))
cmd.AddCommand(NewCmdGetEnv(commonOpts))
cmd.AddCommand(NewCmdGetGit(commonOpts))
cmd.AddCommand(NewCmdGetHelmBin(commonOpts))
cmd.AddCommand(NewCmdGetIssue(commonOpts))
cmd.AddCommand(NewCmdGetIssues(commonOpts))
cmd.AddCommand(NewCmdGetLimits(commonOpts))
cmd.AddCommand(NewCmdGetPipeline(commonOpts))
cmd.AddCommand(NewCmdGetPostPreviewJob(commonOpts))
cmd.AddCommand(NewCmdGetPreview(commonOpts))
cmd.AddCommand(NewCmdGetQuickstartLocation(commonOpts))
cmd.AddCommand(NewCmdGetQuickstarts(commonOpts))
cmd.AddCommand(NewCmdGetRelease(commonOpts))
cmd.AddCommand(NewCmdGetStorage(commonOpts))
cmd.AddCommand(NewCmdGetTeam(commonOpts))
cmd.AddCommand(NewCmdGetTeamRole(commonOpts))
cmd.AddCommand(NewCmdGetToken(commonOpts))
cmd.AddCommand(NewCmdGetTracker(commonOpts))
cmd.AddCommand(NewCmdGetURL(commonOpts))
cmd.AddCommand(NewCmdGetUser(commonOpts))
cmd.AddCommand(NewCmdGetWorkflow(commonOpts))
cmd.AddCommand(NewCmdGetVault(commonOpts))
cmd.AddCommand(NewCmdGetSecret(commonOpts))
cmd.AddCommand(NewCmdGetVaultConfig(commonOpts))
cmd.AddCommand(NewCmdGetPlugins(commonOpts))
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)
}