summaryrefslogtreecommitdiff
path: root/internal/cli/reset
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2022-04-29 22:25:27 +0200
committerValery Piashchynski <[email protected]>2022-04-29 22:25:27 +0200
commit2c0299332da3b84f1a489180c5e0123575a5088e (patch)
tree87ddf626c16587d1547f6ad56ec185a30728751f /internal/cli/reset
parent3474c11c987cb22dc1a7c4b15c957e127d2571ca (diff)
fix terminal output redirect
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'internal/cli/reset')
-rw-r--r--internal/cli/reset/command.go69
-rw-r--r--internal/cli/reset/command_test.go3
2 files changed, 20 insertions, 52 deletions
diff --git a/internal/cli/reset/command.go b/internal/cli/reset/command.go
index ce29d248..084cfeff 100644
--- a/internal/cli/reset/command.go
+++ b/internal/cli/reset/command.go
@@ -1,23 +1,17 @@
package reset
import (
- "fmt"
+ "log"
"sync"
internalRpc "github.com/roadrunner-server/roadrunner/v2/internal/rpc"
- "github.com/fatih/color"
- "github.com/mattn/go-runewidth"
"github.com/roadrunner-server/errors"
"github.com/spf13/cobra"
- "github.com/vbauerster/mpb/v5"
- "github.com/vbauerster/mpb/v5/decor"
)
-var spinnerStyle = []string{"∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙"} //nolint:gochecknoglobals
-
// NewCommand creates `reset` command.
-func NewCommand(cfgFile *string, override *[]string) *cobra.Command { //nolint:funlen
+func NewCommand(cfgFile *string, override *[]string, silent *bool) *cobra.Command {
return &cobra.Command{
Use: "reset",
Short: "Reset workers of all or specific RoadRunner service",
@@ -39,69 +33,42 @@ func NewCommand(cfgFile *string, override *[]string) *cobra.Command { //nolint:f
defer func() { _ = client.Close() }()
- services := args // by default we expect services list from user
- if len(services) == 0 { // but if nothing was passed - request all services list
- if err = client.Call(resetterList, true, &services); err != nil {
+ plugins := args // by default we expect services list from user
+ if len(plugins) == 0 { // but if nothing was passed - request all services list
+ if err = client.Call(resetterList, true, &plugins); err != nil {
return err
}
}
var wg sync.WaitGroup
- wg.Add(len(services))
-
- pr := mpb.New(mpb.WithWaitGroup(&wg), mpb.WithWidth(6)) //nolint:gomnd
-
- for _, service := range services {
- var (
- bar *mpb.Bar
- name = runewidth.FillRight(fmt.Sprintf("Resetting plugin: [%s]", color.HiYellowString(service)), 27)
- result = make(chan interface{})
- )
-
- bar = pr.AddSpinner(
- 1,
- mpb.SpinnerOnMiddle,
- mpb.SpinnerStyle(spinnerStyle),
- mpb.PrependDecorators(decor.Name(name)),
- mpb.AppendDecorators(onComplete(result)),
- )
+ wg.Add(len(plugins))
+ for _, plugin := range plugins {
// simulating some work
- go func(service string, result chan interface{}) {
+ go func(p string) {
+ if !*silent {
+ log.Printf("resetting plugin: [%s] ", p)
+ }
defer wg.Done()
- defer bar.Increment()
var done bool
- <-client.Go(resetterReset, service, &done, nil).Done
+ <-client.Go(resetterReset, p, &done, nil).Done
if err != nil {
- result <- errors.E(op, err)
+ log.Println(err)
return
}
- result <- nil
- }(service, result)
+ if !*silent {
+ log.Printf("plugin reset: [%s]", p)
+ }
+ }(plugin)
}
- pr.Wait()
+ wg.Wait()
return nil
},
}
}
-
-func onComplete(result chan interface{}) decor.Decorator {
- return decor.Any(func(s decor.Statistics) string {
- select {
- case r := <-result:
- if err, ok := r.(error); ok {
- return color.HiRedString(err.Error())
- }
-
- return color.HiGreenString("done")
- default:
- return ""
- }
- })
-}
diff --git a/internal/cli/reset/command_test.go b/internal/cli/reset/command_test.go
index 57801453..509354e2 100644
--- a/internal/cli/reset/command_test.go
+++ b/internal/cli/reset/command_test.go
@@ -10,7 +10,8 @@ import (
func TestCommandProperties(t *testing.T) {
path := ""
- cmd := reset.NewCommand(&path, nil)
+ f := false
+ cmd := reset.NewCommand(&path, nil, &f)
assert.Equal(t, "reset", cmd.Use)
assert.NotNil(t, cmd.RunE)