override RunE function of root subcommands to ensure that help is shown when no arguments are given

Signed-off-by: Christian Richter <c.richter@opencloud.eu>
This commit is contained in:
Christian Richter
2025-12-08 09:40:33 +01:00
committed by Florian Schade
parent 75bcc548d7
commit a9b1bea4f8

View File

@@ -23,7 +23,12 @@ func Execute() error {
})
for _, fn := range register.Commands {
app.AddCommand(fn(cfg))
cmd := fn(cfg)
cmd.RunE = func(cmd *cobra.Command, args []string) error {
cmd.Help()
return nil
}
app.AddCommand(cmd)
}
app.SetArgs(os.Args[1:])
ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP)