Add debug function to print initializing command names
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 8s

Signed-off-by: Jan Tytgat <jan.tytgat@corelayer.eu>
This commit is contained in:
Jan Tytgat
2025-06-03 14:15:48 +02:00
parent 4112e27ba5
commit 1ef456579a

View File

@ -1,6 +1,7 @@
package application package application
import ( import (
"fmt"
"io" "io"
"log/slog" "log/slog"
"os" "os"
@ -24,6 +25,10 @@ var (
outWriter io.Writer = os.Stdout outWriter io.Writer = os.Stdout
) )
func SubCommandInitializePrintNameFunc(cmd *cobra.Command) {
fmt.Println("Initializing:", cmd.Name())
}
func HelpFuncE(cmd *cobra.Command, args []string) error { func HelpFuncE(cmd *cobra.Command, args []string) error {
return cmd.Help() return cmd.Help()
} }
@ -51,7 +56,7 @@ func persistentPreRunFuncE(cmd *cobra.Command, args []string) error {
} }
// Make sure that we show the app help if no commands or flags are passed // Make sure that we show the app help if no commands or flags are passed
if cmd.CalledAs() == appName && runtime.FuncForPC(reflect.ValueOf(cmd.RunE).Pointer()).Name() == runtime.FuncForPC(reflect.ValueOf(runFuncE).Pointer()).Name() { if cmd.CalledAs() == appName && runtime.FuncForPC(reflect.ValueOf(cmd.RunE).Pointer()).Name() == runtime.FuncForPC(reflect.ValueOf(RunCatchFuncE).Pointer()).Name() {
slogd.FromContext(cmd.Context()).LogAttrs(cmd.Context(), slogd.LevelTrace, "overriding command", slog.String("old_function", runtime.FuncForPC(reflect.ValueOf(cmd.RunE).Pointer()).Name()), slog.String("new_function", runtime.FuncForPC(reflect.ValueOf(HelpFuncE).Pointer()).Name())) slogd.FromContext(cmd.Context()).LogAttrs(cmd.Context(), slogd.LevelTrace, "overriding command", slog.String("old_function", runtime.FuncForPC(reflect.ValueOf(cmd.RunE).Pointer()).Name()), slog.String("new_function", runtime.FuncForPC(reflect.ValueOf(HelpFuncE).Pointer()).Name()))
cmd.RunE = HelpFuncE cmd.RunE = HelpFuncE