From ef7291a432cef3fd1a8ab1d79388b6c821801099 Mon Sep 17 00:00:00 2001 From: Sara El-Zayat Date: Tue, 26 Oct 2021 12:06:35 +0200 Subject: [PATCH] Return error for missing arguments (#946) * Return error for missing arguments * linting * Update cmd/gitops/get/clusters/cmd.go Co-authored-by: Simon * Change error message * Update error message Co-authored-by: Simon --- cmd/gitops/get/clusters/cmd.go | 11 ++++++++--- cmd/gitops/get/templates/cmd.go | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/gitops/get/clusters/cmd.go b/cmd/gitops/get/clusters/cmd.go index cd42cc342d..5ee1833985 100644 --- a/cmd/gitops/get/clusters/cmd.go +++ b/cmd/gitops/get/clusters/cmd.go @@ -1,6 +1,7 @@ package clusters import ( + "fmt" "os" "github.com/go-resty/resty/v2" @@ -49,11 +50,15 @@ func getClustersCmdRunE(endpoint *string, client *resty.Client) func(*cobra.Comm defer w.Flush() - if len(args) == 1 { - if clustersGetCmdFlags.Kubeconfig { - return clusters.GetClusterKubeconfig(args[0], r, os.Stdout) + if clustersGetCmdFlags.Kubeconfig { + if len(args) == 0 { + return fmt.Errorf("cluster name is required") } + return clusters.GetClusterKubeconfig(args[0], r, os.Stdout) + } + + if len(args) == 1 { return clusters.GetClusterByName(args[0], r, w) } diff --git a/cmd/gitops/get/templates/cmd.go b/cmd/gitops/get/templates/cmd.go index 9457d23d41..0490ebe608 100644 --- a/cmd/gitops/get/templates/cmd.go +++ b/cmd/gitops/get/templates/cmd.go @@ -65,6 +65,10 @@ func getTemplateCmdRunE(endpoint *string, client *resty.Client) func(*cobra.Comm defer w.Flush() if flags.ListTemplateParameters { + if len(args) == 0 { + return fmt.Errorf("template name is required") + } + return capi.GetTemplateParameters(args[0], r, w) }