mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-05 15:37:19 +00:00
fix: cli exit cleanly (#8267)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
8732183cc6
commit
eeb7e814b5
1 changed files with 16 additions and 6 deletions
|
@ -11,18 +11,28 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cmd := commands.RootCommand()
|
if err := run(); err != nil {
|
||||||
configureLogs(cmd)
|
fmt.Println("Error:", err)
|
||||||
if err := cmd.Execute(); err != nil {
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func configureLogs(cli *cobra.Command) {
|
func run() error {
|
||||||
|
cmd := commands.RootCommand()
|
||||||
|
if err := configureLogs(cmd); err != nil {
|
||||||
|
return fmt.Errorf("Failed to setup logging (%w)", err)
|
||||||
|
}
|
||||||
|
if err := cmd.Execute(); err != nil {
|
||||||
|
return fmt.Errorf("Failed to execute command (%w)", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func configureLogs(cli *cobra.Command) error {
|
||||||
logging.InitFlags(nil)
|
logging.InitFlags(nil)
|
||||||
if err := logging.Setup(logging.TextFormat, 0); err != nil {
|
if err := logging.Setup(logging.TextFormat, 0); err != nil {
|
||||||
fmt.Println("failed to setup logging", err)
|
return err
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
cli.PersistentFlags().AddGoFlagSet(flag.CommandLine)
|
cli.PersistentFlags().AddGoFlagSet(flag.CommandLine)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue