mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -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
@ -49,9 +49,13 @@ func runCreate(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("creating logger: %w", err)
|
||||
}
|
||||
defer log.Sync()
|
||||
fileHandler := file.NewHandler(afero.NewOsFs())
|
||||
spinner := newSpinner(cmd.ErrOrStderr())
|
||||
spinner, err := newSpinnerOrStdout(cmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating spinner: %w", err)
|
||||
}
|
||||
defer spinner.Stop()
|
||||
|
||||
fileHandler := file.NewHandler(afero.NewOsFs())
|
||||
creator := cloudcmd.NewCreator(spinner)
|
||||
c := &createCmd{log: log}
|
||||
return c.create(cmd, creator, fileHandler, spinner)
|
||||
|
@ -213,7 +213,7 @@ func TestCreate(t *testing.T) {
|
||||
|
||||
fileHandler := file.NewHandler(tc.setupFs(require, tc.provider))
|
||||
c := &createCmd{log: logger.NewTest(t)}
|
||||
err := c.create(cmd, tc.creator, fileHandler, nopSpinner{})
|
||||
err := c.create(cmd, tc.creator, fileHandler, &nopSpinner{})
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
|
@ -100,7 +100,7 @@ func TestIAMCreateAWS(t *testing.T) {
|
||||
require.NoError(cmd.Flags().Set("yes", "true"))
|
||||
}
|
||||
|
||||
err := iamCreateAWS(cmd, nopSpinner{}, tc.creator)
|
||||
err := iamCreateAWS(cmd, &nopSpinner{}, tc.creator)
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
|
@ -101,7 +101,7 @@ func TestIAMCreateAzure(t *testing.T) {
|
||||
require.NoError(cmd.Flags().Set("yes", "true"))
|
||||
}
|
||||
|
||||
err := iamCreateAzure(cmd, nopSpinner{}, tc.creator)
|
||||
err := iamCreateAzure(cmd, &nopSpinner{}, tc.creator)
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
|
@ -123,7 +123,7 @@ func TestIAMCreateGCP(t *testing.T) {
|
||||
|
||||
fileHandler := file.NewHandler(tc.setupFs(require, tc.provider))
|
||||
|
||||
err := iamCreateGCP(cmd, nopSpinner{}, fileHandler, tc.creator)
|
||||
err := iamCreateGCP(cmd, &nopSpinner{}, fileHandler, tc.creator)
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
|
@ -165,7 +165,7 @@ func TestInitialize(t *testing.T) {
|
||||
defer cancel()
|
||||
cmd.SetContext(ctx)
|
||||
i := &initCmd{log: logger.NewTest(t)}
|
||||
err := i.initialize(cmd, newDialer, fileHandler, &stubLicenseClient{}, nopSpinner{})
|
||||
err := i.initialize(cmd, newDialer, fileHandler, &stubLicenseClient{}, &nopSpinner{})
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
@ -415,7 +415,7 @@ func TestAttestation(t *testing.T) {
|
||||
cmd.SetContext(ctx)
|
||||
|
||||
i := &initCmd{log: logger.NewTest(t)}
|
||||
err := i.initialize(cmd, newDialer, fileHandler, &stubLicenseClient{}, nopSpinner{})
|
||||
err := i.initialize(cmd, newDialer, fileHandler, &stubLicenseClient{}, &nopSpinner{})
|
||||
assert.Error(err)
|
||||
// make sure the error is actually a TLS handshake error
|
||||
assert.Contains(err.Error(), "transport: authentication handshake failed")
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ func TestTerminate(t *testing.T) {
|
||||
require.NoError(cmd.Flags().Set("yes", "true"))
|
||||
}
|
||||
|
||||
err := terminate(cmd, tc.terminator, fileHandler, nopSpinner{})
|
||||
err := terminate(cmd, tc.terminator, fileHandler, &nopSpinner{})
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
|
Loading…
Reference in New Issue
Block a user