diff --git a/cmd/remote/remote.go b/cmd/remote/remote.go index cd0da57..0c153cc 100644 --- a/cmd/remote/remote.go +++ b/cmd/remote/remote.go @@ -9,16 +9,10 @@ import ( ctxhelper "github.com/gomicro/align/client/context" "github.com/gomicro/align/config" "github.com/spf13/cobra" + "github.com/spf13/viper" ) -var ( - clt client.Clienter - verbose bool -) - -func init() { - RemoteCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose output") -} +var clt client.Clienter var RemoteCmd = &cobra.Command{ Use: "remote", @@ -29,6 +23,7 @@ var RemoteCmd = &cobra.Command{ } func remoteFunc(cmd *cobra.Command, args []string) error { + verbose := viper.GetBool("verbose") ctx := ctxhelper.WithVerbose(context.Background(), verbose) repoDirs, err := clt.GetDirs(ctx, ".") diff --git a/cmd/remote/remote_test.go b/cmd/remote/remote_test.go index ee01a7e..fc30d60 100644 --- a/cmd/remote/remote_test.go +++ b/cmd/remote/remote_test.go @@ -5,12 +5,13 @@ import ( "testing" "github.com/gomicro/align/client/testclient" + "github.com/spf13/viper" "github.com/stretchr/testify/assert" ) func TestRemote(t *testing.T) { - verbose = true - t.Cleanup(func() { verbose = false }) + viper.Set("verbose", true) + t.Cleanup(func() { viper.Set("verbose", false) }) t.Run("calls expected commands", func(t *testing.T) { tc := testclient.New()