-
Notifications
You must be signed in to change notification settings - Fork 199
/
parameters.go
149 lines (127 loc) · 4.72 KB
/
parameters.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
142
143
144
145
146
147
148
149
package main
import (
"get.porter.sh/porter/pkg/porter"
"github.com/spf13/cobra"
)
func buildParametersCommands(p *porter.Porter) *cobra.Command {
cmd := &cobra.Command{
Use: "parameters",
Aliases: []string{"parameter", "param", "params"},
Annotations: map[string]string{"group": "resource"},
Short: "Parameter set commands",
}
cmd.AddCommand(buildParametersEditCommand(p))
cmd.AddCommand(buildParametersGenerateCommand(p))
cmd.AddCommand(buildParametersListCommand(p))
cmd.AddCommand(buildParametersDeleteCommand(p))
cmd.AddCommand(buildParametersShowCommand(p))
return cmd
}
func buildParametersEditCommand(p *porter.Porter) *cobra.Command {
opts := porter.ParameterEditOptions{}
cmd := &cobra.Command{
Use: "edit",
Short: "Edit Parameter Set",
Long: `Edit a named parameter set.`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.EditParameter(opts)
},
}
return cmd
}
func buildParametersGenerateCommand(p *porter.Porter) *cobra.Command {
opts := porter.ParameterOptions{}
cmd := &cobra.Command{
Use: "generate [NAME]",
Short: "Generate Parameter Set",
Long: `Generate a named set of parameters.
The first argument is the name of parameter set you wish to generate. If not
provided, this will default to the bundle name. By default, Porter will
generate a parameter set for the bundle in the current directory. You may also
specify a bundle with --file.
Bundles define 1 or more parameter(s) that are required to interact with a
bundle. The bundle definition defines where the parameter should be delivered
to the bundle, i.e. via DB_USERNAME. A parameter set, on the other hand,
represents the source data that you wish to use when interacting with the
bundle. These will typically be environment variables or files on your local
file system.
When you wish to install, upgrade or delete a bundle, Porter will use the
parameter set to determine where to read the necessary information from and
will then provide it to the bundle in the correct location. `,
Example: ` porter parameter generate
porter parameter generate myparamset --reference getporter/porter-hello:v0.1.0
porter parameter generate myparamset --reference localhost:5000/getporter/porter-hello:v0.1.0 --insecure-registry --force
porter parameter generate myparamset --file myapp/porter.yaml
porter parameter generate myparamset --cnab-file myapp/bundle.json
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args, p.Context)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.GenerateParameters(opts)
},
}
f := cmd.Flags()
f.StringVarP(&opts.File, "file", "f", "",
"Path to the porter manifest file. Defaults to the bundle in the current directory.")
f.StringVar(&opts.CNABFile, "cnab-file", "",
"Path to the CNAB bundle.json file.")
addBundlePullFlags(f, &opts.BundlePullOptions)
return cmd
}
func buildParametersListCommand(p *porter.Porter) *cobra.Command {
opts := porter.ListOptions{}
cmd := &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List parameter sets",
Long: `List named sets of parameters defined by the user.`,
Example: ` porter parameters list [-o table|json|yaml]`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.ParseFormat()
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.ListParameters(opts)
},
}
f := cmd.Flags()
f.StringVarP(&opts.RawFormat, "output", "o", "table",
"Specify an output format. Allowed values: table, json, yaml")
return cmd
}
func buildParametersDeleteCommand(p *porter.Porter) *cobra.Command {
opts := porter.ParameterDeleteOptions{}
return &cobra.Command{
Use: "delete NAME",
Short: "Delete a Parameter Set",
Long: `Delete a named parameter set.`,
PreRunE: func(_ *cobra.Command, args []string) error {
return opts.Validate(args)
},
RunE: func(_ *cobra.Command, _ []string) error {
return p.DeleteParameter(opts)
},
}
}
func buildParametersShowCommand(p *porter.Porter) *cobra.Command {
opts := porter.ParameterShowOptions{}
cmd := &cobra.Command{
Use: "show",
Short: "Show a Parameter Set",
Long: `Show a named parameter set, including all named parameters and their corresponding mappings.`,
Example: ` porter parameter show NAME [-o table|json|yaml]`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.ShowParameter(opts)
},
}
f := cmd.Flags()
f.StringVarP(&opts.RawFormat, "output", "o", "table",
"Specify an output format. Allowed values: table, json, yaml")
return cmd
}