Skip to content

Commit b515296

Browse files
committed
adds silent mode for the tasks rotation
1 parent 1ae2f49 commit b515296

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

cmd/tasks.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ func NewTasksCommand() *cmdr.Command {
289289
),
290290
)
291291

292+
rotateCmd.WithBoolFlag(
293+
cmdr.NewBoolFlag(
294+
"silent",
295+
"s",
296+
vso.Trans("tasks.rotate.options.silent.description"),
297+
false,
298+
),
299+
)
300+
292301
// Add subcommands to stacks
293302
cmd.AddCommand(listCmd)
294303
cmd.AddCommand(newCmd)
@@ -497,6 +506,10 @@ func rotateTasks(cmd *cobra.Command, args []string) error {
497506
if err != nil {
498507
event = "no-system-event"
499508
}
509+
silent, err := cmd.Flags().GetBool("silent")
510+
if err != nil {
511+
return err
512+
}
500513

501-
return core.RotateTasks(event)
514+
return core.RotateTasks(event, silent)
502515
}

core/tasks.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func RunTaskByUnitName(name string) error {
111111

112112
// RotateTasks checks if no other rotators are running, then performs initial
113113
// checks and starts rotating every 5 seconds
114-
func RotateTasks(event string) error {
114+
func RotateTasks(event string, silent bool) error {
115115
if isTasksRotatorIsRunning() {
116116
fmt.Println("Rotator is already running")
117117
return nil
@@ -128,9 +128,11 @@ func RotateTasks(event string) error {
128128
}
129129

130130
for {
131-
fmt.Println("---")
131+
if !silent {
132+
fmt.Println("---")
133+
}
132134
cChecks := GetCommonChecks()
133-
err := runTasksRotator(cChecks, event)
135+
err := runTasksRotator(cChecks, event, silent)
134136
if err != nil {
135137
fmt.Println(err)
136138
}
@@ -140,7 +142,7 @@ func RotateTasks(event string) error {
140142
}
141143

142144
// runTasksRotator checks which tasks should be run and starts rotating
143-
func runTasksRotator(cChecks *CommonChecks, event string) error {
145+
func runTasksRotator(cChecks *CommonChecks, event string, silent bool) error {
144146
var err error
145147
CurrentQueue, err = ListTasksDetailed()
146148
if err != nil {
@@ -166,7 +168,9 @@ func runTasksRotator(cChecks *CommonChecks, event string) error {
166168

167169
CurrentQueue = []Task{}
168170

169-
fmt.Printf("Rotated %d tasks, %d failed, %d success\n", rotatedN, rotatedNFails, rotatedNSuccess)
171+
if !silent {
172+
fmt.Printf("Rotated %d tasks, %d failed, %d success\n", rotatedN, rotatedNFails, rotatedNSuccess)
173+
}
170174

171175
return nil
172176
}

locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ tasks:
232232
options:
233233
privateEvent:
234234
description: "specify the private event to rotate tasks for boot, shutdown, login, and logout"
235+
silent:
236+
description: "don't output the status on each cycle"
235237

236238
waydroid:
237239
description: "Manage the vso waydroid subsystem"

0 commit comments

Comments
 (0)