-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
197 lines (193 loc) · 5.01 KB
/
main.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package main
import (
"fmt"
"github.com/eddiebeazer/flutter-cli-tools/pkgs/fastlane"
"github.com/eddiebeazer/flutter-cli-tools/pkgs/flutter"
"log"
"os"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "flutter-ci",
Usage: "Tools for Flutter and Fastlane CI",
Version: "0.1.0",
UsageText: "Tools for Flutter and Fastlane CI. Please run in your projects root directory",
Suggest: true,
Authors: []*cli.Author{
{
Name: "Edward Beazer",
Email: "[email protected]",
},
},
Commands: []*cli.Command{
{
Name: "release",
Usage: "Commands that help parse release information from a file or Github",
Subcommands: []*cli.Command{
{
Name: "getGithubRelease",
Usage: "Gets a specific release from Github",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "owner",
Aliases: []string{"o"},
Value: "",
Usage: "Owner/Org of the repo",
Required: true,
},
&cli.StringFlag{
Name: "repo",
Aliases: []string{"r"},
Value: "",
Usage: "Name of the repo",
Required: true,
},
&cli.StringFlag{
Name: "version",
Aliases: []string{"v"},
Value: "",
Usage: "Version to fetch from github",
Required: true,
},
},
Action: func(cCtx *cli.Context) error {
owner := cCtx.String("owner")
repo := cCtx.String("repo")
version := cCtx.String("version")
release, err := fastlane.GetGithubRelease(owner, repo, version)
if err != nil {
return err
}
fmt.Printf(*release.TagName)
return nil
},
},
{
Name: "getLatestGithubRelease",
Usage: "Gets the latest Github Release. Can also get drafts with -d",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "owner",
Aliases: []string{"o"},
Value: "",
Usage: "Owner/Org of the repo",
Required: true,
},
&cli.StringFlag{
Name: "repo",
Aliases: []string{"r"},
Value: "",
Usage: "Name of the repo",
Required: true,
},
&cli.BoolFlag{
Name: "draft",
Aliases: []string{"d"},
Value: false,
Usage: "If true, will fetch the latest draft release",
Required: false,
},
},
Action: func(cCtx *cli.Context) error {
owner := cCtx.String("owner")
repo := cCtx.String("repo")
draft := cCtx.Bool("draft")
release, err := fastlane.GetLatestGithubRelease(owner, repo, draft)
if err != nil {
return err
}
fmt.Printf(*release.TagName)
return nil
},
},
},
},
{
Name: "appVersion",
Usage: "Get and set your projects app version",
Subcommands: []*cli.Command{
{
Name: "get",
Usage: "Gets the app version from the pubspec file",
Action: func(cCtx *cli.Context) error {
version, err := flutter.GetAppVersion()
if err != nil {
return err
}
fmt.Printf(version)
return err
},
},
{
Name: "set",
Usage: "Sets the app version",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "version",
Aliases: []string{"v"},
Value: "",
Usage: "Version of the app",
Required: true,
},
&cli.StringFlag{
Name: "build",
Aliases: []string{"b"},
Value: "0",
Usage: "Build number of the version. Defaults to 0",
},
},
Action: func(cCtx *cli.Context) error {
version := cCtx.String("version")
build := cCtx.String("build")
return flutter.SetAppVersion(version, build)
},
},
{
Name: "setFromGithub",
Usage: "Sets the app version from the latest Github release",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "owner",
Aliases: []string{"o"},
Value: "",
Usage: "Owner/Org of the repo",
Required: true,
},
&cli.StringFlag{
Name: "repo",
Aliases: []string{"r"},
Value: "",
Usage: "Name of the repo",
Required: true,
},
&cli.BoolFlag{
Name: "draft",
Aliases: []string{"d"},
Value: false,
Usage: "If true, will fetch the latest draft release",
Required: false,
},
&cli.StringFlag{
Name: "build",
Aliases: []string{"b"},
Usage: "Build number of the version",
},
},
Action: func(cCtx *cli.Context) error {
owner := cCtx.String("owner")
repo := cCtx.String("repo")
draft := cCtx.Bool("draft")
build := cCtx.String("build")
err := flutter.SetAppVersionFromLatestGithubRelease(owner, repo, draft, build)
return err
},
},
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}