From 95868e2fd1da315dbfe52a34f4b18e352dad93a1 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Wed, 21 Nov 2018 08:14:25 +0100 Subject: [PATCH] Uniformate init methods for commands Signed-off-by: Marco Vito Moscaritolo --- cmd/cluster_add_external_worker.go | 1 + cmd/cluster_add_worker.go | 1 + cmd/cluster_addon.go | 2 +- cmd/cluster_addon_install.go | 1 + cmd/cluster_addon_uninstall.go | 1 + cmd/cluster_delete.go | 11 +---------- cmd/cluster_kubeconfig.go | 10 ---------- cmd/cluster_list.go | 10 ---------- cmd/cluster_remove_external_worker.go | 2 +- cmd/context.go | 10 ---------- cmd/context_current.go | 10 ---------- cmd/context_delete.go | 10 ---------- cmd/context_list.go | 10 ---------- cmd/context_use.go | 10 ---------- cmd/ssh_key.go | 11 +---------- cmd/ssh_key_add.go | 11 +---------- cmd/ssh_key_delete.go | 11 +---------- cmd/ssh_key_list.go | 10 ---------- 18 files changed, 10 insertions(+), 122 deletions(-) diff --git a/cmd/cluster_add_external_worker.go b/cmd/cluster_add_external_worker.go index b9e93de3..081cb6d5 100644 --- a/cmd/cluster_add_external_worker.go +++ b/cmd/cluster_add_external_worker.go @@ -188,6 +188,7 @@ An external server must meet the following requirements: func init() { clusterCmd.AddCommand(clusterAddExternalWorkerCmd) + clusterAddExternalWorkerCmd.Flags().StringP("name", "n", "", "Name of the cluster to add the workers to") clusterAddExternalWorkerCmd.Flags().StringP("ip", "i", "", "The IP address of the external node") } diff --git a/cmd/cluster_add_worker.go b/cmd/cluster_add_worker.go index 442cdca4..b615050c 100644 --- a/cmd/cluster_add_worker.go +++ b/cmd/cluster_add_worker.go @@ -142,6 +142,7 @@ You can specify the worker server type as in cluster create.`, func init() { clusterCmd.AddCommand(clusterAddWorkerCmd) + clusterAddWorkerCmd.Flags().StringP("name", "", "", "Name of the cluster to add the workers to") clusterAddWorkerCmd.Flags().String("worker-server-type", "cx11", "Server type used of workers") clusterAddWorkerCmd.Flags().IntP("nodes", "n", 2, "Number of nodes for the cluster") diff --git a/cmd/cluster_addon.go b/cmd/cluster_addon.go index ed873aef..3f230449 100644 --- a/cmd/cluster_addon.go +++ b/cmd/cluster_addon.go @@ -34,8 +34,8 @@ var clusterAddonCmd = &cobra.Command{ func init() { clusterCmd.AddCommand(clusterAddonCmd) - } + func validateAddonSubCommand(cmd *cobra.Command, args []string) error { name, err := cmd.Flags().GetString("name") if err != nil { diff --git a/cmd/cluster_addon_install.go b/cmd/cluster_addon_install.go index 6cff7f87..72d844fc 100644 --- a/cmd/cluster_addon_install.go +++ b/cmd/cluster_addon_install.go @@ -52,5 +52,6 @@ var clusterAddonInstallCmd = &cobra.Command{ func init() { clusterAddonCmd.AddCommand(clusterAddonInstallCmd) + clusterAddonInstallCmd.Flags().StringP("name", "n", "", "Name of the cluster") } diff --git a/cmd/cluster_addon_uninstall.go b/cmd/cluster_addon_uninstall.go index 78e9a115..2879daac 100644 --- a/cmd/cluster_addon_uninstall.go +++ b/cmd/cluster_addon_uninstall.go @@ -52,5 +52,6 @@ var clusterAddonUninstallCmd = &cobra.Command{ func init() { clusterAddonCmd.AddCommand(clusterAddonUninstallCmd) + clusterAddonUninstallCmd.Flags().StringP("name", "n", "", "Name of the cluster") } diff --git a/cmd/cluster_delete.go b/cmd/cluster_delete.go index af1a0697..0897df01 100644 --- a/cmd/cluster_delete.go +++ b/cmd/cluster_delete.go @@ -78,15 +78,6 @@ var clusterDeleteCmd = &cobra.Command{ func init() { clusterCmd.AddCommand(clusterDeleteCmd) - clusterDeleteCmd.Flags().StringP("name", "n", "", "Name of the cluster to delete") - - // Here you will define your flags and configuration settings. - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // clusterDeleteCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // clusterDeleteCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + clusterDeleteCmd.Flags().StringP("name", "n", "", "Name of the cluster to delete") } diff --git a/cmd/cluster_kubeconfig.go b/cmd/cluster_kubeconfig.go index a9cff7f7..a240fcaf 100644 --- a/cmd/cluster_kubeconfig.go +++ b/cmd/cluster_kubeconfig.go @@ -117,14 +117,4 @@ func init() { clusterKubeconfigCmd.Flags().BoolP("print", "p", false, "prints output to stdout") clusterKubeconfigCmd.Flags().BoolP("backup", "b", false, "saves existing config") clusterKubeconfigCmd.Flags().BoolP("force", "f", false, "don't ask to overwrite") - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // clusterKubeconfigCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // clusterKubeconfigCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/cluster_list.go b/cmd/cluster_list.go index b9145cf7..f7800e83 100644 --- a/cmd/cluster_list.go +++ b/cmd/cluster_list.go @@ -51,14 +51,4 @@ var clusterListCmd = &cobra.Command{ func init() { clusterCmd.AddCommand(clusterListCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // clusterListCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // clusterListCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/cluster_remove_external_worker.go b/cmd/cluster_remove_external_worker.go index 1419b682..efa4d643 100644 --- a/cmd/cluster_remove_external_worker.go +++ b/cmd/cluster_remove_external_worker.go @@ -85,7 +85,7 @@ var clusterRemoveExternalWorkerCmd = &cobra.Command{ func init() { clusterCmd.AddCommand(clusterRemoveExternalWorkerCmd) + clusterRemoveExternalWorkerCmd.Flags().StringP("name", "n", "", "Name of the cluster where to remove the worker") clusterRemoveExternalWorkerCmd.Flags().StringP("ip", "i", "", "The IP address of the external node") - } diff --git a/cmd/context.go b/cmd/context.go index f89c576b..0bf07e47 100644 --- a/cmd/context.go +++ b/cmd/context.go @@ -29,14 +29,4 @@ var contextCmd = &cobra.Command{ func init() { rootCmd.AddCommand(contextCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // contextCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // contextCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/context_current.go b/cmd/context_current.go index d1a902fc..f1f32d07 100644 --- a/cmd/context_current.go +++ b/cmd/context_current.go @@ -31,14 +31,4 @@ var currentCmd = &cobra.Command{ func init() { contextCmd.AddCommand(currentCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // currentCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // currentCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/context_delete.go b/cmd/context_delete.go index 18875202..41ca848c 100644 --- a/cmd/context_delete.go +++ b/cmd/context_delete.go @@ -48,14 +48,4 @@ var contextDeleteCmd = &cobra.Command{ func init() { contextCmd.AddCommand(contextDeleteCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // addCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // addCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/context_list.go b/cmd/context_list.go index c61e9c7b..9cb2a119 100644 --- a/cmd/context_list.go +++ b/cmd/context_list.go @@ -44,14 +44,4 @@ var listCmd = &cobra.Command{ func init() { contextCmd.AddCommand(listCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // listCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // listCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/context_use.go b/cmd/context_use.go index 26ac9223..d71bd470 100644 --- a/cmd/context_use.go +++ b/cmd/context_use.go @@ -39,14 +39,4 @@ var useCmd = &cobra.Command{ func init() { contextCmd.AddCommand(useCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // useCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // useCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/ssh_key.go b/cmd/ssh_key.go index af492997..743ddf25 100644 --- a/cmd/ssh_key.go +++ b/cmd/ssh_key.go @@ -32,15 +32,6 @@ Note, that the private key never gets uploaded anywhere. The path is used to con func init() { rootCmd.AddCommand(sshKeyCmd) - sshKeyCmd.Flags().StringP("name", "n", "", "") - - // Here you will define your flags and configuration settings. - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // sshKeyCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // sshKeyCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + sshKeyCmd.Flags().StringP("name", "n", "", "") } diff --git a/cmd/ssh_key_add.go b/cmd/ssh_key_add.go index 9a77226f..ad8170a7 100644 --- a/cmd/ssh_key_add.go +++ b/cmd/ssh_key_add.go @@ -178,17 +178,8 @@ func validateFlags(cmd *cobra.Command, args []string) error { func init() { sshKeyCmd.AddCommand(sshKeyAddCmd) + sshKeyAddCmd.Flags().StringP("name", "n", "", "the name of the key") sshKeyAddCmd.Flags().String("private-key-path", "~/.ssh/id_rsa", "the path to the private key") sshKeyAddCmd.Flags().String("public-key-path", "~/.ssh/id_rsa.pub", "the path to the public key") - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // sshKeyAddCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // sshKeyAddCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/ssh_key_delete.go b/cmd/ssh_key_delete.go index 05b0a257..320b8b40 100644 --- a/cmd/ssh_key_delete.go +++ b/cmd/ssh_key_delete.go @@ -65,15 +65,6 @@ func validateSHHKeyDeleteFlags(cmd *cobra.Command, args []string) error { } func init() { sshKeyCmd.AddCommand(sshKeyDeleteCmd) - sshKeyDeleteCmd.Flags().StringP("name", "n", "", "Name of the ssh-key") - - // Here you will define your flags and configuration settings. - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // sshKeyDeleteCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // sshKeyDeleteCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + sshKeyDeleteCmd.Flags().StringP("name", "n", "", "Name of the ssh-key") } diff --git a/cmd/ssh_key_list.go b/cmd/ssh_key_list.go index b216a55c..a35faba8 100644 --- a/cmd/ssh_key_list.go +++ b/cmd/ssh_key_list.go @@ -49,14 +49,4 @@ to quickly create a Cobra application.`, func init() { sshKeyCmd.AddCommand(sshKeyListCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // sshKeyListCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // sshKeyListCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") }