package cmd import ( "fmt" "loveuer/utodo/internal/opt" "loveuer/utodo/pkg/logger" "loveuer/utodo/pkg/tool" "github.com/spf13/cobra" ) func rootCmd(subCmds ...*cobra.Command) *cobra.Command { cmd := &cobra.Command{ Use: "utodo", Short: "utodo is a todo web/pwa application", PersistentPreRunE: func(cmd *cobra.Command, args []string) error { fmt.Printf("\\/ UTodo %s\n", opt.Version) if opt.Cfg.Debug { logger.SetLogLevel(logger.LogLevelDebug) tool.TablePrinter(opt.Cfg) } return nil }, RunE: rootRun, } cmd.PersistentFlags().BoolVar(&opt.Cfg.Debug, "debug", false, "debug mode") cmd.PersistentFlags().StringVar(&opt.Cfg.Name, "name", "utodo", "app name") cmd.AddCommand(subCmds...) return cmd } func rootRun(cmd *cobra.Command, args []string) error { <-cmd.Context().Done() logger.WarnCtx(cmd.Context(), "received quit signal, exiting...") return nil }