diff --git a/internal/cmd/init.go b/internal/cmd/init.go index 7fecb72..b6e8033 100644 --- a/internal/cmd/init.go +++ b/internal/cmd/init.go @@ -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", @@ -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) }, } } diff --git a/internal/cmd/root.go b/internal/cmd/root.go index f35799a..f093513 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -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 } diff --git a/internal/cmd/run.go b/internal/cmd/run.go index c7499c4..7d12704 100644 --- a/internal/cmd/run.go +++ b/internal/cmd/run.go @@ -23,7 +23,7 @@ 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", @@ -31,7 +31,7 @@ func newRunCmd(cfg tester.CmdConfig) *cobra.Command { if len(args) == 0 { return fmt.Errorf("path is required") } - return tester.Run(cfg, args) + return tester.Run(*cfg, args) }, } }