Skip to content

Commit

Permalink
fix: Make flags work
Browse files Browse the repository at this point in the history
  • Loading branch information
hrk091 committed Sep 21, 2024
1 parent feeb548 commit 82e44d9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/spf13/cobra"
)

func newInitCmd(cfg tester.CmdConfig) *cobra.Command {
func newInitCmd(cfg *tester.CmdConfig) *cobra.Command {
return &cobra.Command{
Use: "init [path to admission policy file]",
Short: "Generate skeleton manifests for writing tests",
Expand All @@ -32,7 +32,7 @@ func newInitCmd(cfg tester.CmdConfig) *cobra.Command {
return fmt.Errorf("path is required")
}
targetFilePath := args[0]
return tester.RunInit(cfg, targetFilePath)
return tester.RunInit(*cfg, targetFilePath)
},
}
}
8 changes: 5 additions & 3 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ func newRootCmd() *cobra.Command {
cmd.PersistentFlags().BoolVarP(&cfg.Verbose, "verbose", "v", false, "Verbose output")
cmd.PersistentFlags().BoolVarP(&cfg.Debug, "debug", "d", false, "Debug output")

initLog(cfg)
cobra.OnInitialize(func() {
initLog(cfg)
})

cmd.AddCommand(newInitCmd(cfg))
cmd.AddCommand(newRunCmd(cfg))
cmd.AddCommand(newInitCmd(&cfg))
cmd.AddCommand(newRunCmd(&cfg))
cmd.AddCommand(newVersionCmd())
return cmd
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import (
"github.com/spf13/cobra"
)

func newRunCmd(cfg tester.CmdConfig) *cobra.Command {
func newRunCmd(cfg *tester.CmdConfig) *cobra.Command {
return &cobra.Command{
Use: "run [path to test manifest]...",
Short: "Run the tests of ValidatingAdmissionPolicy",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return fmt.Errorf("path is required")
}
return tester.Run(cfg, args)
return tester.Run(*cfg, args)
},
}
}

0 comments on commit 82e44d9

Please sign in to comment.