-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgob.go
More file actions
70 lines (66 loc) · 1.91 KB
/
gob.go
File metadata and controls
70 lines (66 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
Copyright © 2023 kcheng.mvp@gmail.com
*/
package main
import (
"context"
"fmt"
"github.com/fatih/color"
"github.com/kcmvp/buildtime"
"github.com/samber/lo"
"github.com/spf13/cobra"
"os"
)
var rootCmd = &cobra.Command{
Use: "gob",
Short: color.GreenString(`Go project boot`),
Long: color.GreenString(`Go project boot, which include lots of useful builder plugins and scaffold
of frameworks`),
//PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
// currentDir, _ := os.Getwd()
// fmt.Println(currentDir)
// fmt.Println(project.RootDir())
// if project.RootDir() != currentDir {
// return fmt.Errorf(color.RedString("Please execute the command in the project root dir"))
// }
// return nil
//},
//ValidArgs: func() []string {
// return lo.FilterMap(project.Plugins(), func(p project.Plugin, _ int) (string, bool) {
// return p.Name, len(p.Url) > 0
// })
//}(),
Args: func(cmd *cobra.Command, args []string) error {
return cobra.MaximumNArgs(1)(cmd, args)
},
//RunE: func(cmd *cobra.Command, args []string) error {
// if len(args) > 0 {
// op := project.PluginByN(args[0])
// if op.IsAbsent() {
// return fmt.Errorf("can not find plugin %s", args[0])
// }
// return op.MustGet().Execute()
// }
// return nil
//},
}
func init() {
rootCmd.SetErrPrefix(color.RedString("Error:"))
rootCmd.SetFlagErrorFunc(func(command *cobra.Command, err error) error {
return lo.IfF(err != nil, func() error {
return fmt.Errorf(color.RedString(err.Error()))
}).Else(nil)
})
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
func main() {
//rootCmd.AddCommand(builder.PluginCmd(), builder.DepCmd(), builder.ExecCmd(), scaffold.InitCmd(), scaffold.DboCmd())
//rootCmd.AddCommand(scaffold.InitCmd())
ws := buildtime.CurrentWS()
fmt.Sprintf("ws is %v", ws)
ctx := context.Background()
if err := rootCmd.ExecuteContext(ctx); err != nil {
os.Exit(1)
}
os.Exit(0)
}