@@ -13,6 +13,7 @@ import (
1313 "github.com/vim-volt/volt/logger"
1414 "github.com/vim-volt/volt/pathutil"
1515 "github.com/vim-volt/volt/transaction"
16+ "github.com/vim-volt/volt/usecase"
1617)
1718
1819type profileCmd struct {
@@ -110,26 +111,28 @@ func (cmd *profileCmd) Run(cmdctx *CmdContext) *Error {
110111 return & Error {Code : 10 , Msg : err .Error ()}
111112 }
112113
113- gateway := args [0 ]
114- switch gateway {
114+ subCmd := args [0 ]
115+ cmdctx .Args = args [1 :]
116+
117+ switch subCmd {
115118 case "set" :
116- err = cmd .doSet (args [ 1 :] )
119+ err = cmd .doSet (cmdctx )
117120 case "show" :
118- err = cmd .doShow (args [ 1 :] )
121+ err = cmd .doShow (cmdctx )
119122 case "list" :
120- err = cmd .doList (args [ 1 :] )
123+ err = cmd .doList (cmdctx )
121124 case "new" :
122- err = cmd .doNew (args [ 1 :] )
125+ err = cmd .doNew (cmdctx )
123126 case "destroy" :
124- err = cmd .doDestroy (args [ 1 :] )
127+ err = cmd .doDestroy (cmdctx )
125128 case "rename" :
126- err = cmd .doRename (args [ 1 :] )
129+ err = cmd .doRename (cmdctx )
127130 case "add" :
128- err = cmd .doAdd (args [ 1 :] )
131+ err = cmd .doAdd (cmdctx )
129132 case "rm" :
130- err = cmd .doRm (args [ 1 :] )
133+ err = cmd .doRm (cmdctx )
131134 default :
132- return & Error {Code : 11 , Msg : "Unknown subcommand: " + gateway }
135+ return & Error {Code : 11 , Msg : "Unknown subcommand: " + subCmd }
133136 }
134137
135138 if err != nil {
@@ -161,7 +164,8 @@ func (*profileCmd) getCurrentProfile() (string, error) {
161164 return lockJSON .CurrentProfileName , nil
162165}
163166
164- func (cmd * profileCmd ) doSet (args []string ) error {
167+ func (cmd * profileCmd ) doSet (cmdctx * CmdContext ) error {
168+ args := cmdctx .Args
165169 // Parse args
166170 createProfile := false
167171 if len (args ) > 0 && args [0 ] == "-n" {
@@ -191,7 +195,8 @@ func (cmd *profileCmd) doSet(args []string) error {
191195 if ! createProfile {
192196 return err
193197 }
194- if err = cmd .doNew ([]string {profileName }); err != nil {
198+ cmdctx .Args = []string {profileName }
199+ if err = cmd .doNew (cmdctx ); err != nil {
195200 return err
196201 }
197202 // Read lock.json again
@@ -231,7 +236,8 @@ func (cmd *profileCmd) doSet(args []string) error {
231236 return nil
232237}
233238
234- func (cmd * profileCmd ) doShow (args []string ) error {
239+ func (cmd * profileCmd ) doShow (cmdctx * CmdContext ) error {
240+ args := cmdctx .Args
235241 if len (args ) == 0 {
236242 cmd .FlagSet ().Usage ()
237243 logger .Error ("'volt profile show' receives profile name." )
@@ -254,25 +260,28 @@ func (cmd *profileCmd) doShow(args []string) error {
254260 }
255261 }
256262
257- return ( & listCmd {}). list ( fmt .Sprintf (`name: %s
263+ format := fmt .Sprintf (`name: %s
258264repos path:
259265{{- with profile %q -}}
260266{{- range .ReposPath }}
261267 {{ . }}
262268{{- end -}}
263269{{- end }}
264- ` , profileName , profileName ))
270+ ` , profileName , profileName )
271+ return usecase .List (os .Stdout , format , cmdctx .LockJSON , cmdctx .Config )
265272}
266273
267- func (cmd * profileCmd ) doList (args [] string ) error {
268- return ( & listCmd {}). list ( `
274+ func (cmd * profileCmd ) doList (cmdctx * CmdContext ) error {
275+ format := `
269276{{- range .Profiles -}}
270277{{- if eq .Name $.CurrentProfileName -}}*{{- else }} {{ end }} {{ .Name }}
271278{{ end -}}
272- ` )
279+ `
280+ return usecase .List (os .Stdout , format , cmdctx .LockJSON , cmdctx .Config )
273281}
274282
275- func (cmd * profileCmd ) doNew (args []string ) error {
283+ func (cmd * profileCmd ) doNew (cmdctx * CmdContext ) error {
284+ args := cmdctx .Args
276285 if len (args ) == 0 {
277286 cmd .FlagSet ().Usage ()
278287 logger .Error ("'volt profile new' receives profile name." )
@@ -316,7 +325,8 @@ func (cmd *profileCmd) doNew(args []string) error {
316325 return nil
317326}
318327
319- func (cmd * profileCmd ) doDestroy (args []string ) error {
328+ func (cmd * profileCmd ) doDestroy (cmdctx * CmdContext ) error {
329+ args := cmdctx .Args
320330 if len (args ) == 0 {
321331 cmd .FlagSet ().Usage ()
322332 logger .Error ("'volt profile destroy' receives profile name." )
@@ -374,7 +384,8 @@ func (cmd *profileCmd) doDestroy(args []string) error {
374384 return merr .ErrorOrNil ()
375385}
376386
377- func (cmd * profileCmd ) doRename (args []string ) error {
387+ func (cmd * profileCmd ) doRename (cmdctx * CmdContext ) error {
388+ args := cmdctx .Args
378389 if len (args ) != 2 {
379390 cmd .FlagSet ().Usage ()
380391 logger .Error ("'volt profile rename' receives profile name." )
@@ -433,7 +444,8 @@ func (cmd *profileCmd) doRename(args []string) error {
433444 return nil
434445}
435446
436- func (cmd * profileCmd ) doAdd (args []string ) error {
447+ func (cmd * profileCmd ) doAdd (cmdctx * CmdContext ) error {
448+ args := cmdctx .Args
437449 // Read lock.json
438450 lockJSON , err := lockjson .Read ()
439451 if err != nil {
@@ -475,7 +487,8 @@ func (cmd *profileCmd) doAdd(args []string) error {
475487 return nil
476488}
477489
478- func (cmd * profileCmd ) doRm (args []string ) error {
490+ func (cmd * profileCmd ) doRm (cmdctx * CmdContext ) error {
491+ args := cmdctx .Args
479492 // Read lock.json
480493 lockJSON , err := lockjson .Read ()
481494 if err != nil {
@@ -519,10 +532,10 @@ func (cmd *profileCmd) doRm(args []string) error {
519532 return nil
520533}
521534
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 ) {
523536 if len (args ) == 0 {
524537 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 )
526539 return "" , nil , nil
527540 }
528541
0 commit comments