-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.go
108 lines (101 loc) · 3 KB
/
index.go
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
Copyright © aksara-tech 2022
*/
package cmd
import (
"fmt"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/wirnat/axara/cmd/v1/files"
"github.com/wirnat/axara/cmd/v1/global"
v1 "github.com/wirnat/axara/cmd/v1/runner"
"github.com/wirnat/axara/cmd/v1/service/getter/go_git"
"os"
"text/template"
)
var generatorCmd = &cobra.Command{
Use: "generate",
Short: "Auto generate Design Pattern",
Example: "axara generate conf.yaml --models User",
Long: `Some folks say that Design Patterns are dead. How foolish. The Design Patterns book is one of the most important books published in our industry. The concepts within should be common rudimentary knowledge for all professional programmers.`,
Run: func(cmd *cobra.Command, args []string) {
app := v1.NewApp(args[0])
err := app.Generate()
if err != nil {
logrus.Fatal(err)
}
},
}
var checkVersion = &cobra.Command{
Use: "version",
Short: "Check Version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Axara version " + VERSION)
},
}
var newConfig = &cobra.Command{
Use: "new",
Short: "New Axara Config file",
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
fmt.Println("❌ require argument filename, example: axara new wirnat_arch")
return
}
file, err := os.Create(args[0] + ".yaml")
if err != nil {
fmt.Println("❌ " + err.Error())
return
}
tmt, err := template.New("new config").Parse(files.New)
if err != nil {
fmt.Println("❌ " + err.Error())
return
}
err = tmt.Execute(file, nil)
if err != nil {
fmt.Println("❌ " + err.Error())
return
}
},
}
var getter = &cobra.Command{
Use: "get",
Aliases: nil,
SuggestFor: nil,
Short: "Get CLI Item from github",
Example: "axara get https://github.com/wirnat/axara-template-go-clean-architecture templates",
Run: func(cmd *cobra.Command, args []string) {
gt := go_git.NewGetter()
if len(args) != 2 {
logrus.Fatal("directory required")
}
err := gt.Get(args[0], args[1])
if err != nil {
logrus.Fatal(err)
}
},
RunE: nil,
PostRun: nil,
PostRunE: nil,
PersistentPostRun: nil,
PersistentPostRunE: nil,
FParseErrWhitelist: cobra.FParseErrWhitelist{},
CompletionOptions: cobra.CompletionOptions{},
TraverseChildren: false,
Hidden: false,
SilenceErrors: false,
SilenceUsage: false,
DisableFlagParsing: false,
DisableAutoGenTag: false,
DisableFlagsInUseLine: false,
DisableSuggestions: false,
SuggestionsMinimumDistance: 0,
}
func init() {
rootCmd.AddCommand(generatorCmd)
rootCmd.AddCommand(checkVersion)
rootCmd.AddCommand(getter)
rootCmd.AddCommand(newConfig)
rootCmd.PersistentFlags().StringSliceVarP(&global.Tags, "tags", "g", []string{}, "List of execute traits/jobs")
rootCmd.PersistentFlags().StringSliceVarP(&global.ExecuteModels, "models", "m", []string{}, "list of execute models")
}