mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-02 22:34:56 -04:00
cli: deactivate spinner for debug logging
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
parent
3c24e3fa01
commit
35d720e657
8 changed files with 34 additions and 12 deletions
|
@ -15,6 +15,7 @@ import (
|
|||
"time"
|
||||
|
||||
tty "github.com/mattn/go-isatty"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -31,6 +32,7 @@ var (
|
|||
type spinnerInterf interface {
|
||||
Start(text string, showDots bool)
|
||||
Stop()
|
||||
io.Writer
|
||||
}
|
||||
|
||||
type spinner struct {
|
||||
|
@ -41,6 +43,17 @@ type spinner struct {
|
|||
spinFunc func(out io.Writer, wg *sync.WaitGroup, stop *atomic.Bool, delay time.Duration, text string, showDots bool)
|
||||
}
|
||||
|
||||
func newSpinnerOrStdout(cmd *cobra.Command) (spinnerInterf, error) {
|
||||
debug, err := cmd.Flags().GetBool("debug")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if debug {
|
||||
return &nopSpinner{cmd.ErrOrStderr()}, nil
|
||||
}
|
||||
return newSpinner(cmd.ErrOrStderr()), nil
|
||||
}
|
||||
|
||||
func newSpinner(writer io.Writer) *spinner {
|
||||
s := &spinner{
|
||||
out: writer,
|
||||
|
@ -108,7 +121,12 @@ func spinNoTTY(out io.Writer, wg *sync.WaitGroup, _ *atomic.Bool, _ time.Duratio
|
|||
fmt.Fprintln(out, text+"...")
|
||||
}
|
||||
|
||||
type nopSpinner struct{}
|
||||
type nopSpinner struct {
|
||||
io.Writer
|
||||
}
|
||||
|
||||
func (s nopSpinner) Start(string, bool) {}
|
||||
func (s nopSpinner) Stop() {}
|
||||
func (s *nopSpinner) Start(string, bool) {}
|
||||
func (s *nopSpinner) Stop() {}
|
||||
func (s *nopSpinner) Write(p []byte) (n int, err error) {
|
||||
return s.Writer.Write(p)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue