1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/cmd/cli/kubectl-kyverno/main.go
Charles-Edouard Brétéché dc71610df7
refactor: cli commands tests and error handling (#8367)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-09-13 09:53:19 +00:00

39 lines
812 B
Go

package main
import (
"flag"
"fmt"
"os"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/experimental"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/log"
"github.com/spf13/cobra"
)
func main() {
cmd, err := setup()
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
}
func setup() (*cobra.Command, error) {
cmd := commands.RootCommand(experimental.IsEnabled())
if err := configureLogs(cmd); err != nil {
return nil, fmt.Errorf("Failed to setup logging (%w)", err)
}
return cmd, nil
}
func configureLogs(cli *cobra.Command) error {
if err := log.Configure(); err != nil {
return err
}
cli.PersistentFlags().AddGoFlagSet(flag.CommandLine)
return nil
}