Skip to content

Commit b7727f8

Browse files
committed
force] add force flag on clean/hosts command
1 parent 721ffed commit b7727f8

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

cli/command/clean.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type cleanOptions struct {
6161
host string
6262
only []string
6363
withoutRecycle bool
64+
force bool
6465
}
6566

6667
func checkCleanOptions(curveadm *cli.CurveAdm, options cleanOptions) error {
@@ -97,6 +98,7 @@ func NewCleanCommand(curveadm *cli.CurveAdm) *cobra.Command {
9798
flags.StringVar(&options.host, "host", "*", "Specify service host")
9899
flags.StringSliceVarP(&options.only, "only", "o", CLEAN_ITEMS, "Specify clean item")
99100
flags.BoolVar(&options.withoutRecycle, "no-recycle", false, "Remove data directory directly instead of recycle chunks")
101+
flags.BoolVarP(&options.force, "force", "f", false, "Never prompt")
100102

101103
return cmd
102104
}
@@ -142,6 +144,12 @@ func runClean(curveadm *cli.CurveAdm, options cleanOptions) error {
142144
}
143145

144146
// 3) confirm by user
147+
// 3) force stop
148+
if options.force {
149+
curveadm.WriteOut(tui.PromptCancelOpetation("clean service"))
150+
return pb.Run()
151+
}
152+
145153
if pass := tui.ConfirmYes(tui.PromptCleanService(options.role, options.host, options.only)); !pass {
146154
curveadm.WriteOut(tui.PromptCancelOpetation("clean service"))
147155
return errno.ERR_CANCEL_OPERATION

cli/command/hosts/commit.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const (
4242
type commitOptions struct {
4343
filename string
4444
slient bool
45+
force bool
4546
}
4647

4748
func NewCommitCommand(curveadm *cli.CurveAdm) *cobra.Command {
@@ -61,6 +62,7 @@ func NewCommitCommand(curveadm *cli.CurveAdm) *cobra.Command {
6162

6263
flags := cmd.Flags()
6364
flags.BoolVarP(&options.slient, "slient", "s", false, "Slient output for config commit")
65+
flags.BoolVarP(&options.force, "force", "f", false, "Never prompt")
6466

6567
return cmd
6668
}
@@ -95,11 +97,13 @@ func runCommit(curveadm *cli.CurveAdm, options commitOptions) error {
9597
return err
9698
}
9799

98-
// 2) confirm by user
99-
pass := tui.ConfirmYes("Do you want to continue?")
100-
if !pass {
101-
curveadm.WriteOut(tui.PromptCancelOpetation("commit hosts"))
102-
return errno.ERR_CANCEL_OPERATION
100+
// 2) confirm by user or force commit
101+
if !options.force {
102+
pass := tui.ConfirmYes("Do you want to continue?")
103+
if !pass {
104+
curveadm.WriteOut(tui.PromptCancelOpetation("commit hosts"))
105+
return errno.ERR_CANCEL_OPERATION
106+
}
103107
}
104108

105109
// 3) update hosts in database

0 commit comments

Comments
 (0)