From 66382ad3146daf8051f0173d55fc4fa702863c7e Mon Sep 17 00:00:00 2001 From: Eslam-Nawara Date: Mon, 4 Nov 2024 13:59:13 +0200 Subject: [PATCH] add no-color flag to tfrobot --- tfrobot/cmd/cancel.go | 2 +- tfrobot/cmd/deploy.go | 7 ++++++- tfrobot/cmd/load.go | 7 ++++++- tfrobot/cmd/setup.go | 6 +++++- tfrobot/go.mod | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tfrobot/cmd/cancel.go b/tfrobot/cmd/cancel.go index d46145e9..73d7a0c0 100644 --- a/tfrobot/cmd/cancel.go +++ b/tfrobot/cmd/cancel.go @@ -31,7 +31,7 @@ var cancelCmd = &cobra.Command{ return err } - tfPluginClient, err := setup(cfg, debug) + tfPluginClient, err := setup(cfg, debug, false) if err != nil { return err } diff --git a/tfrobot/cmd/deploy.go b/tfrobot/cmd/deploy.go index 6638b33d..a4f2e286 100644 --- a/tfrobot/cmd/deploy.go +++ b/tfrobot/cmd/deploy.go @@ -31,6 +31,10 @@ var deployCmd = &cobra.Command{ if err != nil { return errors.Wrap(err, "error in output file") } + noColor, err := cmd.Flags().GetBool("no-color") + if err != nil { + return err + } if err = checkOutputFile(outputPath); err != nil { return err @@ -41,7 +45,7 @@ var deployCmd = &cobra.Command{ return err } - tfPluginClient, err := setup(cfg, debug) + tfPluginClient, err := setup(cfg, debug, noColor) if err != nil { return err } @@ -64,4 +68,5 @@ func init() { deployCmd.Flags().BoolP("debug", "d", false, "allow debug logs") deployCmd.Flags().StringP("config", "c", "", "path to config file") deployCmd.Flags().StringP("output", "o", "output.yaml", "path to output file") + deployCmd.Flags().Bool("no-color", false, "disable output styling") } diff --git a/tfrobot/cmd/load.go b/tfrobot/cmd/load.go index e61d3759..2174a9a0 100644 --- a/tfrobot/cmd/load.go +++ b/tfrobot/cmd/load.go @@ -31,6 +31,10 @@ var loadCmd = &cobra.Command{ if err != nil { return errors.Wrap(err, "error in output file") } + noColor, err := cmd.Flags().GetBool("no-color") + if err != nil { + return err + } if err = checkOutputFile(outputPath); err != nil { return err @@ -41,7 +45,7 @@ var loadCmd = &cobra.Command{ return err } - tfPluginClient, err := setup(cfg, debug) + tfPluginClient, err := setup(cfg, debug, noColor) if err != nil { return err } @@ -60,4 +64,5 @@ func init() { loadCmd.Flags().BoolP("debug", "d", false, "allow debug logs") loadCmd.Flags().StringP("config", "c", "", "path to config file") loadCmd.Flags().StringP("output", "o", "output.yaml", "path to output file") + loadCmd.Flags().Bool("no-color", false, "disable output styling") } diff --git a/tfrobot/cmd/setup.go b/tfrobot/cmd/setup.go index e4131a75..324fc3d9 100644 --- a/tfrobot/cmd/setup.go +++ b/tfrobot/cmd/setup.go @@ -18,7 +18,7 @@ const jsonExt = ".json" var allowedExt = []string{".yml", ".yaml", jsonExt} -func setup(conf tfrobot.Config, debug bool) (deployer.TFPluginClient, error) { +func setup(conf tfrobot.Config, debug, noColor bool) (deployer.TFPluginClient, error) { network := conf.Network log.Debug().Str("network", network).Send() @@ -30,9 +30,13 @@ func setup(conf tfrobot.Config, debug bool) (deployer.TFPluginClient, error) { deployer.WithRMBTimeout(30), deployer.WithNetwork(network), } + if debug { opts = append(opts, deployer.WithLogs()) } + if noColor { + opts = append(opts, deployer.WithNoColorLogs()) + } return deployer.NewTFPluginClient(mnemonic, opts...) } diff --git a/tfrobot/go.mod b/tfrobot/go.mod index 77d7bc2c..23b12933 100644 --- a/tfrobot/go.mod +++ b/tfrobot/go.mod @@ -6,6 +6,7 @@ require ( github.com/cosmos/go-bip39 v1.0.0 github.com/go-playground/validator/v10 v10.17.0 github.com/hashicorp/go-multierror v1.1.1 + github.com/pkg/errors v0.9.1 github.com/rs/zerolog v1.33.0 github.com/sethvargo/go-retry v0.3.0 github.com/spf13/cobra v1.8.1 @@ -52,7 +53,6 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b // indirect github.com/pierrec/xxHash v0.1.5 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rs/cors v1.10.1 // indirect github.com/spf13/pflag v1.0.5 // indirect