5
5
"fmt"
6
6
"io"
7
7
"net/http"
8
- "os"
9
- "path/filepath"
10
8
"strings"
11
9
"time"
12
10
"unicode/utf8"
@@ -27,7 +25,7 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
27
25
provisioner string
28
26
provisionerTags []string
29
27
variablesFile string
30
- variables []string
28
+ commandLineVariables []string
31
29
disableEveryone bool
32
30
requireActiveVersion bool
33
31
@@ -129,15 +127,21 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
129
127
return err
130
128
}
131
129
130
+ userVariableValues , err := ParseUserVariableValues (
131
+ variablesFile ,
132
+ commandLineVariables )
133
+ if err != nil {
134
+ return err
135
+ }
136
+
132
137
job , err := createValidTemplateVersion (inv , createValidTemplateVersionArgs {
133
- Message : message ,
134
- Client : client ,
135
- Organization : organization ,
136
- Provisioner : codersdk .ProvisionerType (provisioner ),
137
- FileID : resp .ID ,
138
- ProvisionerTags : tags ,
139
- VariablesFile : variablesFile ,
140
- Variables : variables ,
138
+ Message : message ,
139
+ Client : client ,
140
+ Organization : organization ,
141
+ Provisioner : codersdk .ProvisionerType (provisioner ),
142
+ FileID : resp .ID ,
143
+ ProvisionerTags : tags ,
144
+ UserVariableValues : userVariableValues ,
141
145
})
142
146
if err != nil {
143
147
return err
@@ -197,12 +201,12 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
197
201
{
198
202
Flag : "variable" ,
199
203
Description : "Specify a set of values for Terraform-managed variables." ,
200
- Value : clibase .StringArrayOf (& variables ),
204
+ Value : clibase .StringArrayOf (& commandLineVariables ),
201
205
},
202
206
{
203
207
Flag : "var" ,
204
208
Description : "Alias of --variable." ,
205
- Value : clibase .StringArrayOf (& variables ),
209
+ Value : clibase .StringArrayOf (& commandLineVariables ),
206
210
},
207
211
{
208
212
Flag : "provisioner-tag" ,
@@ -267,40 +271,27 @@ type createValidTemplateVersionArgs struct {
267
271
Provisioner codersdk.ProvisionerType
268
272
FileID uuid.UUID
269
273
270
- VariablesFile string
271
- Variables []string
272
-
273
274
// Template is only required if updating a template's active version.
274
275
Template * codersdk.Template
275
276
// ReuseParameters will attempt to reuse params from the Template field
276
277
// before prompting the user. Set to false to always prompt for param
277
278
// values.
278
- ReuseParameters bool
279
- ProvisionerTags map [string ]string
279
+ ReuseParameters bool
280
+ ProvisionerTags map [string ]string
281
+ UserVariableValues []codersdk.VariableValue
280
282
}
281
283
282
284
func createValidTemplateVersion (inv * clibase.Invocation , args createValidTemplateVersionArgs ) (* codersdk.TemplateVersion , error ) {
283
285
client := args .Client
284
286
285
- variableValues , err := loadVariableValuesFromFile (args .VariablesFile )
286
- if err != nil {
287
- return nil , err
288
- }
289
-
290
- variableValuesFromKeyValues , err := loadVariableValuesFromOptions (args .Variables )
291
- if err != nil {
292
- return nil , err
293
- }
294
- variableValues = append (variableValues , variableValuesFromKeyValues ... )
295
-
296
287
req := codersdk.CreateTemplateVersionRequest {
297
288
Name : args .Name ,
298
289
Message : args .Message ,
299
290
StorageMethod : codersdk .ProvisionerStorageMethodFile ,
300
291
FileID : args .FileID ,
301
292
Provisioner : args .Provisioner ,
302
293
ProvisionerTags : args .ProvisionerTags ,
303
- UserVariableValues : variableValues ,
294
+ UserVariableValues : args . UserVariableValues ,
304
295
}
305
296
if args .Template != nil {
306
297
req .TemplateID = args .Template .ID
@@ -364,23 +355,6 @@ func createValidTemplateVersion(inv *clibase.Invocation, args createValidTemplat
364
355
return & version , nil
365
356
}
366
357
367
- // prettyDirectoryPath returns a prettified path when inside the users
368
- // home directory. Falls back to dir if the users home directory cannot
369
- // discerned. This function calls filepath.Clean on the result.
370
- func prettyDirectoryPath (dir string ) string {
371
- dir = filepath .Clean (dir )
372
- homeDir , err := os .UserHomeDir ()
373
- if err != nil {
374
- return dir
375
- }
376
- prettyDir := dir
377
- if strings .HasPrefix (prettyDir , homeDir ) {
378
- prettyDir = strings .TrimPrefix (prettyDir , homeDir )
379
- prettyDir = "~" + prettyDir
380
- }
381
- return prettyDir
382
- }
383
-
384
358
func ParseProvisionerTags (rawTags []string ) (map [string ]string , error ) {
385
359
tags := map [string ]string {}
386
360
for _ , rawTag := range rawTags {
0 commit comments