From 3742b98636d542ae4ca00b02380af8aa192f47e7 Mon Sep 17 00:00:00 2001 From: "mengjiao.liu" Date: Fri, 19 Mar 2021 15:00:18 +0800 Subject: [PATCH] Clean up code duplicate --- references/cli/capability.go | 6 +++--- references/cli/help.go | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/references/cli/capability.go b/references/cli/capability.go index 0535f1056..3d9030a08 100644 --- a/references/cli/capability.go +++ b/references/cli/capability.go @@ -73,7 +73,7 @@ func NewCapCenterConfigCommand(ioStreams cmdutil.IOStreams) *cobra.Command { return nil }, } - cmd.PersistentFlags().StringP("token", "t", "", "Github Repo token") + AddTokenVarFlags(cmd) return cmd } @@ -107,7 +107,7 @@ func NewCapInstallCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Comm return nil }, } - cmd.PersistentFlags().StringP("token", "t", "", "Github Repo token") + AddTokenVarFlags(cmd) return cmd } @@ -144,7 +144,7 @@ func NewCapUninstallCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Co return common.RemoveCapability(env.Namespace, c, newClient, name, ioStreams) }, } - cmd.PersistentFlags().StringP("token", "t", "", "Github Repo token") + AddTokenVarFlags(cmd) return cmd } diff --git a/references/cli/help.go b/references/cli/help.go index d90c7a0cb..d318a7a87 100644 --- a/references/cli/help.go +++ b/references/cli/help.go @@ -47,3 +47,8 @@ func PrintHelpByTag(cmd *cobra.Command, all []*cobra.Command, tag string) { cmd.Println(table.String()) cmd.Println() } + +// AddTokenVarFlags adds token flag to a command +func AddTokenVarFlags(cmd *cobra.Command) { + cmd.PersistentFlags().StringP("token", "t", "", "Github Repo token") +}