Skip to content

Commit 1502487

Browse files
committed
refactor: absorb enable,disable commands to profile
1 parent 34e53ea commit 1502487

File tree

5 files changed

+24
-181
lines changed

5 files changed

+24
-181
lines changed

gateway/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Cmd interface {
2424

2525
// CmdContext is a data transfer object between Subcmd and Gateway layer.
2626
type CmdContext struct {
27+
Cmd string
2728
Args []string
2829
LockJSON *lockjson.LockJSON
2930
Config *config.Config

gateway/disable.go

Lines changed: 0 additions & 89 deletions
This file was deleted.

gateway/enable.go

Lines changed: 0 additions & 89 deletions
This file was deleted.

gateway/profile.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ var profileSubCmd = make(map[string]func([]string) error)
2424

2525
func init() {
2626
cmdMap["profile"] = &profileCmd{}
27+
cmdMap["enable"] = cmdMap["profile"]
28+
cmdMap["disable"] = cmdMap["profile"]
2729
}
2830

2931
func (cmd *profileCmd) ProhibitRootExecution(args []string) bool {
@@ -69,6 +71,14 @@ Command
6971
profile rename {old} {new}
7072
Rename profile {old} to {new}.
7173
74+
enable {repository} [{repository2} ...]
75+
This is shortcut of:
76+
volt profile add -current {repository} [{repository2} ...]
77+
78+
disable {repository} [{repository2} ...]
79+
This is shortcut of:
80+
volt profile rm -current {repository} [{repository2} ...]
81+
7282
profile add [-current | {name}] {repository} [{repository2} ...]
7383
Add one or more repositories to profile {name}.
7484
@@ -103,7 +113,7 @@ Quick example
103113

104114
func (cmd *profileCmd) Run(cmdctx *CmdContext) *Error {
105115
// Parse args
106-
args, err := cmd.parseArgs(cmdctx.Args)
116+
args, err := cmd.parseArgs(cmdctx)
107117
if err == ErrShowedHelp {
108118
return nil
109119
}
@@ -142,9 +152,18 @@ func (cmd *profileCmd) Run(cmdctx *CmdContext) *Error {
142152
return nil
143153
}
144154

145-
func (cmd *profileCmd) parseArgs(args []string) ([]string, error) {
155+
func (cmd *profileCmd) parseArgs(cmdctx *CmdContext) ([]string, error) {
156+
switch cmdctx.Cmd {
157+
case "enable":
158+
cmdctx.Cmd = "profile"
159+
cmdctx.Args = append([]string{"add", "-current"}, cmdctx.Args...)
160+
case "disable":
161+
cmdctx.Cmd = "profile"
162+
cmdctx.Args = append([]string{"rm", "-current"}, cmdctx.Args...)
163+
}
164+
146165
fs := cmd.FlagSet()
147-
fs.Parse(args)
166+
fs.Parse(cmdctx.Args)
148167
if cmd.helped {
149168
return nil, ErrShowedHelp
150169
}

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func run(args []string) (int, string) {
6363
}
6464

6565
result := c.Run(&gateway.CmdContext{
66+
Cmd: subCmd,
6667
Args: args,
6768
LockJSON: lockJSON,
6869
Config: cfg,

0 commit comments

Comments
 (0)