From d78856fc991abc681bef1adfccaff416ee904c5e Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Tue, 21 May 2024 15:12:54 +0200 Subject: [PATCH] refactor(cmd): add a 'root' command make a subcommand to check the configuration, hence leaving room for other upcoming commands Signed-off-by: Xavier Coulon --- cmd/check.go | 10 +--------- cmd/root.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 cmd/root.go diff --git a/cmd/check.go b/cmd/check.go index 66cfd4b..9ea1821 100644 --- a/cmd/check.go +++ b/cmd/check.go @@ -12,14 +12,6 @@ import ( "github.com/spf13/cobra" ) -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. -func Execute() { - if err := NewCheckCmd().Execute(); err != nil { - os.Exit(1) - } -} - // checkCmd represents the base command when called without any subcommands func NewCheckCmd() *cobra.Command { @@ -28,7 +20,7 @@ func NewCheckCmd() *cobra.Command { var verbose bool checkCmd := &cobra.Command{ - Use: "argocd-checker --base-dir=$(pwd) --apps apps-of-apps,apps --components components --verbose=false", + Use: "check --base-dir=$(pwd) --apps apps-of-apps,apps --components components --verbose=false", Short: "Checks the Argo CD configuration", Args: cobra.ExactArgs(0), diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..e9d4456 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,30 @@ +package cmd + +import ( + "os" + + "github.com/spf13/cobra" +) + +// rootCmd represents the base command when called without any subcommands +var rootCmd = &cobra.Command{ + Use: "argocd-checker", +} + +func Execute() { + err := rootCmd.Execute() + if err != nil { + os.Exit(1) + } +} + +var kubeconfig string +var verbose bool + +func init() { + rootCmd.PersistentFlags().StringVar(&kubeconfig, "kubeconfig", "", "Path to the kubeconfig file (default to $KUBECONFIG or $HOME/.kube/config)") + rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Verbose output") + rootCmd.PersistentFlags().BoolP("toggle", "t", false, "Help message for toggle") + + rootCmd.AddCommand(NewCheckCmd()) +}