From a2926e64ec1a5f6a78193796464b3cc769a58451 Mon Sep 17 00:00:00 2001 From: Olivier CANO Date: Fri, 3 Apr 2020 13:20:06 +0200 Subject: [PATCH 1/2] feat(init): handle empty config --- go.mod | 2 +- go.sum | 2 ++ internal/namespaces/init/init.go | 6 +----- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 94a61c3954..71d7c454b4 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/mattn/go-colorable v0.1.4 github.com/mattn/go-isatty v0.0.11 github.com/pkg/errors v0.9.1 // indirect - github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200331160105-1181c3dc1bcd + github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200403105108-eb943ac1f1dc github.com/sergi/go-diff v1.0.0 // indirect github.com/spf13/cobra v0.0.5 github.com/spf13/pflag v1.0.5 // indirect diff --git a/go.sum b/go.sum index 55087d5b7a..45f166d765 100644 --- a/go.sum +++ b/go.sum @@ -61,6 +61,8 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6 h1:C1/pvkxkGN/H03mDxLzItaceYJDBk1HdClgR15suAzI= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200331160105-1181c3dc1bcd h1:ICQFQOSIOyt5n1RxOCAg1rq+DFLunpJpAK2ttjdGhUU= github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200331160105-1181c3dc1bcd/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200403105108-eb943ac1f1dc h1:YJloAPPmGOEF+nufGL4a9Ppj6jnIMs8FjIorEM3ZBoE= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.6.0.20200403105108-eb943ac1f1dc/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= diff --git a/internal/namespaces/init/init.go b/internal/namespaces/init/init.go index ded047a78e..bc45343d0d 100644 --- a/internal/namespaces/init/init.go +++ b/internal/namespaces/init/init.go @@ -124,14 +124,10 @@ func initCommand() *core.Command { // Check if a config exists // Actual creation of the new config is done in the Run() - newConfig := false config, err := scw.LoadConfig() - if err != nil { - newConfig = true - } // If it is not a new config, ask if we want to override the existing config - if !newConfig { + if err == nil && !config.IsEmpty() { _, _ = interactive.PrintlnWithoutIndent(` Current config is located at ` + scw.GetConfigPath() + ` ` + terminal.Style(fmt.Sprint(config), color.Faint) + ` From a8046286cdad0e33af4d62138c1d4e867fc1ee34 Mon Sep 17 00:00:00 2001 From: Olivier CANO Date: Fri, 3 Apr 2020 13:54:43 +0200 Subject: [PATCH 2/2] fix tests --- internal/matomo/matomo.go | 4 ++-- internal/namespaces/init/init.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/matomo/matomo.go b/internal/matomo/matomo.go index 9583065c03..040e8dbea2 100644 --- a/internal/matomo/matomo.go +++ b/internal/matomo/matomo.go @@ -111,11 +111,11 @@ func generateRandNumber() string { return bigRand.String() } -// IsTelemetryDisabled returns true when the Opt-In send_telemetry attribute in the config is set. +// IsTelemetryDisabled returns false when the Opt-In send_telemetry attribute in the config is set. func IsTelemetryDisabled() bool { config, err := scw.LoadConfig() if err != nil { return false } - return !config.SendTelemetry + return config.SendTelemetry == nil || !*config.SendTelemetry } diff --git a/internal/namespaces/init/init.go b/internal/namespaces/init/init.go index bc45343d0d..2e03a48b40 100644 --- a/internal/namespaces/init/init.go +++ b/internal/namespaces/init/init.go @@ -241,7 +241,7 @@ func initCommand() *core.Command { } if args.SendTelemetry != nil { - config.SendTelemetry = *args.SendTelemetry + config.SendTelemetry = args.SendTelemetry } // Update active profile