Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
refactor(cmd): add a 'root' command (#14)
Browse files Browse the repository at this point in the history
make a subcommand to check the configuration, hence
leaving room for other upcoming commands

also, update the GitHub action Dockerfile

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored May 22, 2024
1 parent 95b5b75 commit 8cda939
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ COPY --from=builder /usr/src/app/check-argocd /usr/local/bin/
# Run as non-root user
USER 1001

ENTRYPOINT ["/usr/local/bin/check-argocd"]
ENTRYPOINT ["/usr/local/bin/check-argocd", "check"]
10 changes: 1 addition & 9 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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),

Expand Down
30 changes: 30 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -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())
}

0 comments on commit 8cda939

Please sign in to comment.