Skip to content
This repository was archived by the owner on Aug 24, 2024. It is now read-only.

Commit 576b07c

Browse files
committed
Add a proper CLI interface
1 parent 15794f8 commit 576b07c

File tree

3 files changed

+68
-19
lines changed

3 files changed

+68
-19
lines changed

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ go 1.17
44

55
require (
66
github.com/davecgh/go-spew v1.1.0
7+
github.com/urfave/cli/v2 v2.3.0
78
google.golang.org/api v0.70.0
89
)
910

1011
require (
1112
cloud.google.com/go/compute v1.3.0 // indirect
13+
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
1214
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
1315
github.com/golang/protobuf v1.5.2 // indirect
1416
github.com/googleapis/gax-go/v2 v2.1.1 // indirect
17+
github.com/russross/blackfriday/v2 v2.0.1 // indirect
18+
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
1519
go.opencensus.io v0.23.0 // indirect
1620
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
1721
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWH
6868
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
6969
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
7070
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
71+
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
72+
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
7173
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
7274
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7375
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
@@ -171,12 +173,18 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
171173
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
172174
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
173175
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
176+
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
177+
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
178+
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
179+
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
174180
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
175181
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
176182
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
177183
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
178184
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
179185
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
186+
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
187+
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
180188
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
181189
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
182190
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

main.go

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,83 @@ import (
99

1010
"google.golang.org/api/androidpublisher/v3"
1111
"google.golang.org/api/option"
12+
13+
"github.com/urfave/cli/v2"
1214
)
1315

1416
func main() {
15-
args := os.Args[1:]
16-
if len(args) != 2 {
17-
fmt.Println("Usage: packageId credentialsFilePath")
18-
os.Exit(1)
17+
var credsFile string
18+
var pkg string
19+
20+
app := &cli.App{
21+
Name: "Android Publisher",
22+
Usage: "Access the Android Publisher API",
23+
24+
Flags: []cli.Flag{
25+
&cli.StringFlag{
26+
Name: "cred",
27+
Aliases: []string{"c"},
28+
Value: "google-play-api-key.json",
29+
Usage: "Load Google Play API Credentials from `FILE`",
30+
Destination: &credsFile,
31+
EnvVars: []string{"GOOGLE_PLAY_API_CREDENTIALS_FILE"},
32+
},
33+
&cli.StringFlag{
34+
Name: "package",
35+
Aliases: []string{"p"},
36+
Usage: "App Package ID",
37+
Destination: &pkg,
38+
EnvVars: []string{"APB_PACKAGE"},
39+
Required: true,
40+
},
41+
},
42+
Commands: []*cli.Command{
43+
{
44+
Name: "trackInfo",
45+
Usage: "Display Info about a track",
46+
Action: func(c *cli.Context) error {
47+
return trackInfo(c.Context, pkg, credsFile)
48+
},
49+
},
50+
},
1951
}
20-
pkg := args[0]
21-
credsFile := args[1]
2252

23-
ctx := context.Background()
24-
androidpublisherService, err := androidpublisher.NewService(ctx, option.WithCredentialsFile(credsFile))
53+
err := app.Run(os.Args)
2554
if err != nil {
2655
log.Fatal(err)
2756
}
57+
}
2858

29-
var appEdit androidpublisher.AppEdit
30-
c1 := androidpublisherService.Edits.Insert(pkg, &appEdit)
31-
rsp, err := c1.Do()
59+
func trackInfo(ctx context.Context, pkg string, credsFile string) error {
60+
androidpublisherService, err := androidpublisher.NewService(ctx, option.WithCredentialsFile(credsFile))
3261
if err != nil {
33-
log.Fatal(err)
62+
return err
3463
}
3564

36-
editId := rsp.Id
65+
var appEdit androidpublisher.AppEdit
66+
editCreate := androidpublisherService.Edits.Insert(pkg, &appEdit)
67+
editCreateRsp, err := editCreate.Do()
68+
if err != nil {
69+
return err
70+
}
71+
editId := editCreateRsp.Id
3772

38-
c3 := androidpublisherService.Edits.Tracks.Get(pkg, editId, "production")
39-
rsp3, err := c3.Do()
73+
c := androidpublisherService.Edits.Tracks.Get(pkg, editId, "production")
74+
rsp, err := c.Do()
4075
if err != nil {
41-
log.Fatal(err)
76+
return err
4277
}
4378

44-
if len(rsp3.Releases) != 1 {
79+
if len(rsp.Releases) != 1 {
4580
log.Fatal("Should have received one response")
4681
}
47-
release := rsp3.Releases[0]
82+
release := rsp.Releases[0]
4883

4984
json, err := json.MarshalIndent(release, "", " ")
5085
if err != nil {
51-
log.Fatal(err)
86+
return err
5287
}
5388
fmt.Println(string(json))
89+
90+
return nil
5491
}

0 commit comments

Comments
 (0)