🎉 start the project

This commit is contained in:
loveuer
2025-07-09 22:50:23 +08:00
commit 84348f9eaf
31 changed files with 9990 additions and 0 deletions

22
internal/cmd/cmd.go Normal file
View File

@ -0,0 +1,22 @@
package cmd
import (
"context"
"os"
"github.com/spf13/cobra"
)
var (
root *cobra.Command
)
func Init(ctx context.Context) {
root = rootCmd()
}
func Execute(ctx context.Context) {
if err := root.ExecuteContext(ctx); err != nil {
os.Exit(1)
}
}

41
internal/cmd/root.go Normal file
View File

@ -0,0 +1,41 @@
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.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
}

7
internal/opt/opt.go Normal file
View File

@ -0,0 +1,7 @@
package opt
type config struct {
Debug bool
}
var Cfg = &config{}

5
internal/opt/var.go Normal file
View File

@ -0,0 +1,5 @@
package opt
var (
Version = "<UNKNOWN>"
)