Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 0f18046

Browse files
nwtDavid Chung
authored andcommitted
Fix template flag handling (#480)
Signed-off-by: Noah Treuhaft <[email protected]>
1 parent 9057644 commit 0f18046

File tree

6 files changed

+34
-35
lines changed

6 files changed

+34
-35
lines changed

cmd/cli/flavor/flavor.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
104104
return group_types.Index{Group: group.ID(groupID), Sequence: groupSequence}
105105
}
106106

107+
templateFlags, toJSON, _, processTemplate := base.TemplateProcessor(plugins)
108+
107109
///////////////////////////////////////////////////////////////////////////////////
108110
// validate
109-
validateTemplateFlags, toJSON, _, validateProcessTemplate := base.TemplateProcessor(plugins)
110111
validate := &cobra.Command{
111112
Use: "validate",
112113
Short: "Validate a flavor configuration",
@@ -117,7 +118,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
117118
os.Exit(1)
118119
}
119120

120-
view, err := validateProcessTemplate(*flavorPropertiesURL)
121+
view, err := processTemplate(*flavorPropertiesURL)
121122
if err != nil {
122123
return err
123124
}
@@ -130,12 +131,11 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
130131
return flavorPlugin.Validate(types.AnyBytes(buff), allocationMethodFromFlags())
131132
},
132133
}
133-
validate.Flags().AddFlagSet(validateTemplateFlags)
134+
validate.Flags().AddFlagSet(templateFlags)
134135
addAllocationMethodFlags(validate)
135136

136137
///////////////////////////////////////////////////////////////////////////////////
137138
// prepare
138-
prepareTemplateFlags, toJSON, _, prepareProcessTemplate := base.TemplateProcessor(plugins)
139139
prepare := &cobra.Command{
140140
Use: "prepare <instance Spec template url>",
141141
Short: "Prepare provisioning inputs for an instance. Read from stdin if url is '-'",
@@ -146,14 +146,14 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
146146
os.Exit(1)
147147
}
148148

149-
flavorProperties, err := prepareProcessTemplate(*flavorPropertiesURL)
149+
flavorProperties, err := processTemplate(*flavorPropertiesURL)
150150
if err != nil {
151151
return err
152152
}
153153

154154
view, err := base.ReadFromStdinIfElse(
155155
func() bool { return args[0] == "-" },
156-
func() (string, error) { return prepareProcessTemplate(args[0]) },
156+
func() (string, error) { return processTemplate(args[0]) },
157157
toJSON,
158158
)
159159
if err != nil {
@@ -181,29 +181,28 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
181181
return err
182182
},
183183
}
184-
prepare.Flags().AddFlagSet(prepareTemplateFlags)
184+
prepare.Flags().AddFlagSet(templateFlags)
185185
addAllocationMethodFlags(prepare)
186186
indexFlags(prepare)
187187

188188
///////////////////////////////////////////////////////////////////////////////////
189189
// healthy
190-
healthyTemplateFlags, toJSON, _, healthyProcessTemplate := base.TemplateProcessor(plugins)
191190
healthy := &cobra.Command{
192191
Use: "healthy",
193192
Short: "checks if an instance is considered healthy",
194193
}
195194
tags := healthy.Flags().StringSlice("tags", []string{}, "Tags to filter")
196195
id := healthy.Flags().String("id", "", "ID of resource")
197196
logicalID := healthy.Flags().String("logical-id", "", "Logical ID of resource")
198-
healthy.Flags().AddFlagSet(healthyTemplateFlags)
197+
healthy.Flags().AddFlagSet(templateFlags)
199198
healthy.RunE = func(cmd *cobra.Command, args []string) error {
200199

201200
if len(args) != 0 {
202201
cmd.Usage()
203202
os.Exit(1)
204203
}
205204

206-
flavorProperties, err := healthyProcessTemplate(*flavorPropertiesURL)
205+
flavorProperties, err := processTemplate(*flavorPropertiesURL)
207206
if err != nil {
208207
return err
209208
}

cmd/cli/group/group.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
6363
return nil
6464
}
6565

66+
templateFlags, toJSON, fromJSON, processTemplate := base.TemplateProcessor(plugins)
67+
6668
///////////////////////////////////////////////////////////////////////////////////
6769
// commit
68-
tflags, toJSON, _, processTemplate := base.TemplateProcessor(plugins)
6970
commit := &cobra.Command{
7071
Use: "commit <group configuration url>",
7172
Short: "Commit a group configuration. Read from stdin if url is '-'",
@@ -101,7 +102,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
101102
return err
102103
},
103104
}
104-
commit.Flags().AddFlagSet(tflags)
105+
commit.Flags().AddFlagSet(templateFlags)
105106

106107
///////////////////////////////////////////////////////////////////////////////////
107108
// free
@@ -164,7 +165,6 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
164165

165166
///////////////////////////////////////////////////////////////////////////////////
166167
// inspect
167-
inspectTemplateFlags, _, fromJSON, _ := base.TemplateProcessor(plugins)
168168
inspect := &cobra.Command{
169169
Use: "inspect <group ID>",
170170
Short: "Insepct a group. Returns the raw configuration associated with a group",
@@ -203,7 +203,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
203203
return err
204204
},
205205
}
206-
inspect.Flags().AddFlagSet(inspectTemplateFlags)
206+
inspect.Flags().AddFlagSet(templateFlags)
207207

208208
///////////////////////////////////////////////////////////////////////////////////
209209
// destroy

cmd/cli/instance/instance.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
5656
return nil
5757
}
5858

59+
templateFlags, toJSON, _, processTemplate := base.TemplateProcessor(plugins)
60+
5961
///////////////////////////////////////////////////////////////////////////////////
6062
// validate
61-
validateTemplateFlags, toJSON, _, validateProcessTemplate := base.TemplateProcessor(plugins)
6263
validate := &cobra.Command{
6364
Use: "validate <instance configuration url>",
6465
Short: "Validates an instance configuration. Read from stdin if url is '-'",
@@ -71,7 +72,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
7172

7273
view, err := base.ReadFromStdinIfElse(
7374
func() bool { return args[0] == "-" },
74-
func() (string, error) { return validateProcessTemplate(args[0]) },
75+
func() (string, error) { return processTemplate(args[0]) },
7576
toJSON,
7677
)
7778
if err != nil {
@@ -85,11 +86,10 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
8586
return err
8687
},
8788
}
88-
validate.Flags().AddFlagSet(validateTemplateFlags)
89+
validate.Flags().AddFlagSet(templateFlags)
8990

9091
///////////////////////////////////////////////////////////////////////////////////
9192
// provision
92-
provisionTemplateFlags, toJSON, _, provisionProcessTemplate := base.TemplateProcessor(plugins)
9393
provision := &cobra.Command{
9494
Use: "provision <instance configuration url>",
9595
Short: "Provisions an instance. Read from stdin if url is '-'",
@@ -102,7 +102,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
102102

103103
view, err := base.ReadFromStdinIfElse(
104104
func() bool { return args[0] == "-" },
105-
func() (string, error) { return provisionProcessTemplate(args[0]) },
105+
func() (string, error) { return processTemplate(args[0]) },
106106
toJSON,
107107
)
108108
if err != nil {
@@ -121,7 +121,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
121121
return err
122122
},
123123
}
124-
provision.Flags().AddFlagSet(provisionTemplateFlags)
124+
provision.Flags().AddFlagSet(templateFlags)
125125

126126
///////////////////////////////////////////////////////////////////////////////////
127127
// destroy

cmd/cli/manager/manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
7878
}
7979
pretend := cmd.PersistentFlags().Bool("pretend", false, "Don't actually make changes; explain where appropriate")
8080

81+
templateFlags, toJSON, fromJSON, processTemplate := base.TemplateProcessor(plugins)
82+
8183
///////////////////////////////////////////////////////////////////////////////////
8284
// commit
83-
tflags, toJSON, _, processTemplate := base.TemplateProcessor(plugins)
8485
commit := &cobra.Command{
8586
Use: "commit <template_URL>",
8687
Short: "Commit a multi-group configuration, as specified by the URL. Read from stdin if url is '-'",
@@ -150,11 +151,10 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
150151
return nil
151152
},
152153
}
153-
commit.Flags().AddFlagSet(tflags)
154+
commit.Flags().AddFlagSet(templateFlags)
154155

155156
///////////////////////////////////////////////////////////////////////////////////
156157
// inspect
157-
inspectFlags, _, fromJSON, _ := base.TemplateProcessor(plugins)
158158
inspect := &cobra.Command{
159159
Use: "inspect",
160160
Short: "Inspect returns the plugin configurations known by the manager",
@@ -200,7 +200,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
200200
return nil
201201
},
202202
}
203-
inspect.Flags().AddFlagSet(inspectFlags)
203+
inspect.Flags().AddFlagSet(templateFlags)
204204

205205
cmd.AddCommand(commit, inspect)
206206

cmd/cli/resource/resource.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
5454
return nil
5555
}
5656

57+
templateFlags, toJSON, fromJSON, processTemplate := base.TemplateProcessor(plugins)
58+
5759
///////////////////////////////////////////////////////////////////////////////////
5860
// commit
59-
commitTemplateFlags, toJSON, _, commitProcessTemplate := base.TemplateProcessor(plugins)
6061
commit := &cobra.Command{
6162
Use: "commit <template URL>",
6263
Short: "Commit a resource configuration at url. Read from stdin if url is '-'",
@@ -68,7 +69,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
6869

6970
view, err := base.ReadFromStdinIfElse(
7071
func() bool { return args[0] == "-" },
71-
func() (string, error) { return commitProcessTemplate(args[0]) },
72+
func() (string, error) { return processTemplate(args[0]) },
7273
toJSON,
7374
)
7475
if err != nil {
@@ -91,16 +92,15 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
9192
return err
9293
},
9394
}
94-
commit.Flags().AddFlagSet(commitTemplateFlags)
95+
commit.Flags().AddFlagSet(templateFlags)
9596

9697
///////////////////////////////////////////////////////////////////////////////////
9798
// destroy
98-
destroyTemplateFlags, toJSON, _, destroyProcessTemplate := base.TemplateProcessor(plugins)
9999
destroy := &cobra.Command{
100100
Use: "destroy <template URL>",
101101
Short: "Destroy a resource configuration specified by the URL. Read from stdin if url is '-'",
102102
}
103-
destroy.Flags().AddFlagSet(destroyTemplateFlags)
103+
destroy.Flags().AddFlagSet(templateFlags)
104104
destroy.RunE = func(cmd *cobra.Command, args []string) error {
105105

106106
if len(args) != 1 {
@@ -110,7 +110,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
110110

111111
view, err := base.ReadFromStdinIfElse(
112112
func() bool { return args[0] == "-" },
113-
func() (string, error) { return destroyProcessTemplate(args[0]) },
113+
func() (string, error) { return processTemplate(args[0]) },
114114
toJSON,
115115
)
116116
if err != nil {
@@ -135,7 +135,6 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
135135

136136
///////////////////////////////////////////////////////////////////////////////////
137137
// describe
138-
describeTemplateFlags, toJSON, fromJSON, describeProcessTemplate := base.TemplateProcessor(plugins)
139138
describe := &cobra.Command{
140139
Use: "describe <template URL>",
141140
Short: "Describe a resource configuration specified by the URL. Read from stdin if url is '-'",
@@ -148,7 +147,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
148147

149148
view, err := base.ReadFromStdinIfElse(
150149
func() bool { return args[0] == "-" },
151-
func() (string, error) { return describeProcessTemplate(args[0]) },
150+
func() (string, error) { return processTemplate(args[0]) },
152151
toJSON,
153152
)
154153
if err != nil {
@@ -175,7 +174,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
175174
return err
176175
},
177176
}
178-
describe.Flags().AddFlagSet(describeTemplateFlags)
177+
describe.Flags().AddFlagSet(templateFlags)
179178

180179
cmd.AddCommand(
181180
commit,

cmd/cli/template/template.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ func init() {
2222
// Command is the entrypoint
2323
func Command(plugins func() discovery.Plugins) *cobra.Command {
2424

25+
templateFlags, _, _, processTemplate := base.TemplateProcessor(plugins)
26+
2527
///////////////////////////////////////////////////////////////////////////////////
2628
// template
27-
tflags, _, _, processTemplate := base.TemplateProcessor(plugins)
2829
cmd := &cobra.Command{
2930
Use: "template <url>",
3031
Short: "Render an infrakit template at given url. If url is '-', read from stdin",
@@ -53,7 +54,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
5354
return nil
5455
},
5556
}
56-
cmd.Flags().AddFlagSet(tflags)
57+
cmd.Flags().AddFlagSet(templateFlags)
5758

5859
format := &cobra.Command{
5960
Use: "format json|yaml",

0 commit comments

Comments
 (0)