From e502c51a5b53e3b91b6f41c666e04da83611852e Mon Sep 17 00:00:00 2001 From: Tuna Date: Mon, 30 Oct 2017 14:12:50 +0700 Subject: [PATCH] de-duplicate common flags --- cmd/down.go | 4 +--- cmd/root.go | 7 +++++++ cmd/up.go | 6 ++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/down.go b/cmd/down.go index 60595ccf1a7..a957b5bc5cb 100644 --- a/cmd/down.go +++ b/cmd/down.go @@ -5,7 +5,6 @@ import ( "github.com/ksonnet/kubecfg/pkg/kubecfg" "github.com/spf13/cobra" - "k8s.io/client-go/pkg/api" ) var downCmd = &cobra.Command{ @@ -52,7 +51,6 @@ var downCmd = &cobra.Command{ func init() { RootCmd.AddCommand(downCmd) - downCmd.Flags().StringP("namespace", "", api.NamespaceDefault, "Specify namespace for the KubeApps components") downCmd.Flags().Int64("grace-period", -1, "Number of seconds given to resources to terminate gracefully. A negative value is ignored") - downCmd.Flags().String("path", "", "Specify folder contains the manifests") + bindFlags(downCmd) } diff --git a/cmd/root.go b/cmd/root.go index 6b7c81fe159..72465f136e2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,6 +12,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/client-go/discovery" "k8s.io/client-go/dynamic" + "k8s.io/client-go/pkg/api" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" ) @@ -29,6 +30,12 @@ var RootCmd = &cobra.Command{ }, } +func bindFlags(cmd *cobra.Command) { + cmd.Flags().StringP("namespace", "", api.NamespaceDefault, "Specify namespace for the KubeApps components") + cmd.Flags().String("path", "", "Specify folder contains the manifests") + +} + func appendObj(res *[]*unstructured.Unstructured) filepath.WalkFunc { return func(path string, info os.FileInfo, err error) error { if err != nil { diff --git a/cmd/up.go b/cmd/up.go index 9e9be2e4d75..316ff72796b 100644 --- a/cmd/up.go +++ b/cmd/up.go @@ -2,12 +2,11 @@ package cmd import ( "os" + "path/filepath" "github.com/ksonnet/kubecfg/metadata" "github.com/ksonnet/kubecfg/pkg/kubecfg" "github.com/spf13/cobra" - "k8s.io/client-go/pkg/api" - "path/filepath" ) const ( @@ -68,7 +67,6 @@ var upCmd = &cobra.Command{ func init() { RootCmd.AddCommand(upCmd) - upCmd.Flags().StringP("namespace", "", api.NamespaceDefault, "Specify namespace for the KubeApps components") upCmd.Flags().Bool("dry-run", false, "Provides output to be submitted to the server") - upCmd.Flags().String("path", "", "Specify folder contains the manifests") + bindFlags(upCmd) }