-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
138 lines (126 loc) · 3.09 KB
/
app.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package cli
import (
"os"
"github.com/make-go-great/color-go"
"github.com/urfave/cli/v2"
)
const (
name = "changeloguru"
usage = "generate changelog from conventional commits"
flagVerbose = "verbose"
flagVersion = "version"
flagFrom = "from"
flagTo = "to"
flagScope = "scope"
flagRepository = "repository"
flagOutput = "output"
flagFilename = "filename"
flagFiletype = "filetype"
flagDryRun = "dry-run"
flagInteractive = "interactive"
commandGenerate = "generate"
commandVersion = "version"
usageGenerate = "generate changelog"
usageCommandVersion = "git commit when build changeloguru"
usageVerbose = "show what is going on"
usageFlagVersion = "`VERSION` to generate, follow Semantic Versioning"
usageFrom = "from `COMMIT`, which is kinda new commit, default is latest commit"
usageTo = "to `COMMIT`, which is kinda old commit, default is oldest commit"
usageScope = "scope to generate"
usageRepository = "`REPOSITORY` directory path"
usageOutput = "`OUTPUT` directory path"
usageFilename = "output `FILENAME`"
usageFiletype = "output `FILETYPE`"
usageDryRun = "demo run without actually changing anything"
usageInteractive = "interactive mode, default is true"
)
var (
aliasGenerate = []string{"g", "gen"}
aliasVerbose = []string{"v"}
aliasInteractive = []string{"i"}
)
type App struct {
cliApp *cli.App
}
func NewApp() *App {
a := &action{}
cliApp := &cli.App{
Name: name,
Usage: usage,
Commands: []*cli.Command{
{
Name: commandGenerate,
Aliases: aliasGenerate,
Usage: usageGenerate,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: flagVerbose,
Aliases: aliasVerbose,
Usage: usageVerbose,
},
&cli.StringFlag{
Name: flagVersion,
Usage: usageFlagVersion,
},
&cli.StringFlag{
Name: flagFrom,
Usage: usageFrom,
},
&cli.StringFlag{
Name: flagTo,
Usage: usageTo,
},
&cli.StringSliceFlag{
Name: flagScope,
Usage: usageScope,
},
&cli.StringFlag{
Name: flagRepository,
Usage: usageRepository,
Value: defaultRepository,
},
&cli.StringFlag{
Name: flagOutput,
Usage: usageOutput,
Value: defaultOutput,
},
&cli.StringFlag{
Name: flagFilename,
Usage: usageFilename,
Value: defaultFilename,
},
&cli.StringFlag{
Name: flagFiletype,
Usage: usageFiletype,
Value: defaultFiletype,
},
&cli.BoolFlag{
Name: flagDryRun,
Usage: usageDryRun,
},
&cli.BoolFlag{
Name: flagInteractive,
Usage: usageInteractive,
Aliases: aliasInteractive,
Value: true,
},
},
Action: a.RunGenerate,
},
{
Name: commandVersion,
Usage: usageCommandVersion,
Action: a.RunVersion,
},
},
Action: a.RunHelp,
}
return &App{
cliApp: cliApp,
}
}
func (a *App) Run() {
if err := a.cliApp.Run(os.Args); err != nil {
color.PrintAppError(name, err.Error())
}
}