Files
utodo/internal/cmd/root.go
2025-07-10 22:39:41 +08:00

43 lines
946 B
Go

package cmd
import (
"fmt"
"loveuer/utodo/internal/opt"
"gitea.loveuer.com/yizhisec/packages/logger"
"gitea.loveuer.com/yizhisec/packages/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
}