From 9a25a8e424b2c62a05c4486b675eb96645e04cab Mon Sep 17 00:00:00 2001 From: Mateusz Gozdek Date: Thu, 24 Sep 2020 16:18:09 +0200 Subject: [PATCH] cli/cmd: consistently use diags.HasErrors() for checking diagnostics Part of #994. Signed-off-by: Mateusz Gozdek --- cli/cmd/cluster.go | 2 +- cli/cmd/component-apply.go | 5 ++--- cli/cmd/component-delete.go | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cli/cmd/cluster.go b/cli/cmd/cluster.go index 45db4c73c..f82fead16 100644 --- a/cli/cmd/cluster.go +++ b/cli/cmd/cluster.go @@ -45,7 +45,7 @@ func init() { // and returns created objects to the caller for further use. func initialize(contextLogger *log.Entry) (*terraform.Executor, platform.Platform, *config.Config, string) { lokoConfig, diags := getLokoConfig() - if len(diags) > 0 { + if diags.HasErrors() { contextLogger.Fatal(diags) } diff --git a/cli/cmd/component-apply.go b/cli/cmd/component-apply.go index 15af519f1..8a40b0987 100644 --- a/cli/cmd/component-apply.go +++ b/cli/cmd/component-apply.go @@ -62,12 +62,11 @@ func runApply(cmd *cobra.Command, args []string) { } lokoConfig, diags := getLokoConfig() - if len(diags) > 0 { + if diags.HasErrors() { contextLogger.Fatal(diags) } componentsToApply := args - if len(componentsToApply) == 0 { for _, component := range lokoConfig.RootConfig.Components { componentsToApply = append(componentsToApply, component.Name) @@ -96,7 +95,7 @@ func applyComponents(lokoConfig *config.Config, kubeconfig []byte, componentName componentConfigBody := lokoConfig.LoadComponentConfigBody(componentName) - if diags := component.LoadConfig(componentConfigBody, lokoConfig.EvalContext); len(diags) > 0 { + if diags := component.LoadConfig(componentConfigBody, lokoConfig.EvalContext); diags.HasErrors() { fmt.Printf("%v\n", diags) return diags } diff --git a/cli/cmd/component-delete.go b/cli/cmd/component-delete.go index dd4a56275..31a93b419 100644 --- a/cli/cmd/component-delete.go +++ b/cli/cmd/component-delete.go @@ -63,7 +63,7 @@ func runDelete(cmd *cobra.Command, args []string) { } lokoConfig, diags := getLokoConfig() - if len(diags) > 0 { + if diags.HasErrors() { contextLogger.Fatal(diags) }