@@ -13,6 +13,7 @@ import (
13
13
"github.com/vim-volt/volt/logger"
14
14
"github.com/vim-volt/volt/pathutil"
15
15
"github.com/vim-volt/volt/transaction"
16
+ "github.com/vim-volt/volt/usecase"
16
17
)
17
18
18
19
type profileCmd struct {
@@ -110,26 +111,28 @@ func (cmd *profileCmd) Run(cmdctx *CmdContext) *Error {
110
111
return & Error {Code : 10 , Msg : err .Error ()}
111
112
}
112
113
113
- gateway := args [0 ]
114
- switch gateway {
114
+ subCmd := args [0 ]
115
+ cmdctx .Args = args [1 :]
116
+
117
+ switch subCmd {
115
118
case "set" :
116
- err = cmd .doSet (args [ 1 :] )
119
+ err = cmd .doSet (cmdctx )
117
120
case "show" :
118
- err = cmd .doShow (args [ 1 :] )
121
+ err = cmd .doShow (cmdctx )
119
122
case "list" :
120
- err = cmd .doList (args [ 1 :] )
123
+ err = cmd .doList (cmdctx )
121
124
case "new" :
122
- err = cmd .doNew (args [ 1 :] )
125
+ err = cmd .doNew (cmdctx )
123
126
case "destroy" :
124
- err = cmd .doDestroy (args [ 1 :] )
127
+ err = cmd .doDestroy (cmdctx )
125
128
case "rename" :
126
- err = cmd .doRename (args [ 1 :] )
129
+ err = cmd .doRename (cmdctx )
127
130
case "add" :
128
- err = cmd .doAdd (args [ 1 :] )
131
+ err = cmd .doAdd (cmdctx )
129
132
case "rm" :
130
- err = cmd .doRm (args [ 1 :] )
133
+ err = cmd .doRm (cmdctx )
131
134
default :
132
- return & Error {Code : 11 , Msg : "Unknown subcommand: " + gateway }
135
+ return & Error {Code : 11 , Msg : "Unknown subcommand: " + subCmd }
133
136
}
134
137
135
138
if err != nil {
@@ -161,7 +164,8 @@ func (*profileCmd) getCurrentProfile() (string, error) {
161
164
return lockJSON .CurrentProfileName , nil
162
165
}
163
166
164
- func (cmd * profileCmd ) doSet (args []string ) error {
167
+ func (cmd * profileCmd ) doSet (cmdctx * CmdContext ) error {
168
+ args := cmdctx .Args
165
169
// Parse args
166
170
createProfile := false
167
171
if len (args ) > 0 && args [0 ] == "-n" {
@@ -191,7 +195,8 @@ func (cmd *profileCmd) doSet(args []string) error {
191
195
if ! createProfile {
192
196
return err
193
197
}
194
- if err = cmd .doNew ([]string {profileName }); err != nil {
198
+ cmdctx .Args = []string {profileName }
199
+ if err = cmd .doNew (cmdctx ); err != nil {
195
200
return err
196
201
}
197
202
// Read lock.json again
@@ -231,7 +236,8 @@ func (cmd *profileCmd) doSet(args []string) error {
231
236
return nil
232
237
}
233
238
234
- func (cmd * profileCmd ) doShow (args []string ) error {
239
+ func (cmd * profileCmd ) doShow (cmdctx * CmdContext ) error {
240
+ args := cmdctx .Args
235
241
if len (args ) == 0 {
236
242
cmd .FlagSet ().Usage ()
237
243
logger .Error ("'volt profile show' receives profile name." )
@@ -254,25 +260,28 @@ func (cmd *profileCmd) doShow(args []string) error {
254
260
}
255
261
}
256
262
257
- return ( & listCmd {}). list ( fmt .Sprintf (`name: %s
263
+ format := fmt .Sprintf (`name: %s
258
264
repos path:
259
265
{{- with profile %q -}}
260
266
{{- range .ReposPath }}
261
267
{{ . }}
262
268
{{- end -}}
263
269
{{- end }}
264
- ` , profileName , profileName ))
270
+ ` , profileName , profileName )
271
+ return usecase .List (os .Stdout , format , cmdctx .LockJSON , cmdctx .Config )
265
272
}
266
273
267
- func (cmd * profileCmd ) doList (args [] string ) error {
268
- return ( & listCmd {}). list ( `
274
+ func (cmd * profileCmd ) doList (cmdctx * CmdContext ) error {
275
+ format := `
269
276
{{- range .Profiles -}}
270
277
{{- if eq .Name $.CurrentProfileName -}}*{{- else }} {{ end }} {{ .Name }}
271
278
{{ end -}}
272
- ` )
279
+ `
280
+ return usecase .List (os .Stdout , format , cmdctx .LockJSON , cmdctx .Config )
273
281
}
274
282
275
- func (cmd * profileCmd ) doNew (args []string ) error {
283
+ func (cmd * profileCmd ) doNew (cmdctx * CmdContext ) error {
284
+ args := cmdctx .Args
276
285
if len (args ) == 0 {
277
286
cmd .FlagSet ().Usage ()
278
287
logger .Error ("'volt profile new' receives profile name." )
@@ -316,7 +325,8 @@ func (cmd *profileCmd) doNew(args []string) error {
316
325
return nil
317
326
}
318
327
319
- func (cmd * profileCmd ) doDestroy (args []string ) error {
328
+ func (cmd * profileCmd ) doDestroy (cmdctx * CmdContext ) error {
329
+ args := cmdctx .Args
320
330
if len (args ) == 0 {
321
331
cmd .FlagSet ().Usage ()
322
332
logger .Error ("'volt profile destroy' receives profile name." )
@@ -374,7 +384,8 @@ func (cmd *profileCmd) doDestroy(args []string) error {
374
384
return merr .ErrorOrNil ()
375
385
}
376
386
377
- func (cmd * profileCmd ) doRename (args []string ) error {
387
+ func (cmd * profileCmd ) doRename (cmdctx * CmdContext ) error {
388
+ args := cmdctx .Args
378
389
if len (args ) != 2 {
379
390
cmd .FlagSet ().Usage ()
380
391
logger .Error ("'volt profile rename' receives profile name." )
@@ -433,7 +444,8 @@ func (cmd *profileCmd) doRename(args []string) error {
433
444
return nil
434
445
}
435
446
436
- func (cmd * profileCmd ) doAdd (args []string ) error {
447
+ func (cmd * profileCmd ) doAdd (cmdctx * CmdContext ) error {
448
+ args := cmdctx .Args
437
449
// Read lock.json
438
450
lockJSON , err := lockjson .Read ()
439
451
if err != nil {
@@ -475,7 +487,8 @@ func (cmd *profileCmd) doAdd(args []string) error {
475
487
return nil
476
488
}
477
489
478
- func (cmd * profileCmd ) doRm (args []string ) error {
490
+ func (cmd * profileCmd ) doRm (cmdctx * CmdContext ) error {
491
+ args := cmdctx .Args
479
492
// Read lock.json
480
493
lockJSON , err := lockjson .Read ()
481
494
if err != nil {
@@ -519,10 +532,10 @@ func (cmd *profileCmd) doRm(args []string) error {
519
532
return nil
520
533
}
521
534
522
- func (cmd * profileCmd ) parseAddArgs (lockJSON * lockjson.LockJSON , gateway string , args []string ) (string , []pathutil.ReposPath , error ) {
535
+ func (cmd * profileCmd ) parseAddArgs (lockJSON * lockjson.LockJSON , subCmd string , args []string ) (string , []pathutil.ReposPath , error ) {
523
536
if len (args ) == 0 {
524
537
cmd .FlagSet ().Usage ()
525
- logger .Errorf ("'volt profile %s' receives profile name and one or more repositories." , gateway )
538
+ logger .Errorf ("'volt profile %s' receives profile name and one or more repositories." , subCmd )
526
539
return "" , nil , nil
527
540
}
528
541
0 commit comments