@@ -43,8 +43,36 @@ func main() {
43
43
{
44
44
Name : "trackInfo" ,
45
45
Usage : "Display Info about a track" ,
46
- Action : func (c * cli.Context ) error {
47
- return trackInfo (c .Context , pkg , credsFile )
46
+ Subcommands : []* cli.Command {
47
+ {
48
+ Name : "production" ,
49
+ Aliases : []string {"p" },
50
+ Action : func (c * cli.Context ) error {
51
+ return trackInfo (c .Context , pkg , credsFile , c .Command .Name )
52
+ },
53
+ },
54
+ {
55
+ Name : "alpha" ,
56
+ Aliases : []string {"a" },
57
+ Action : func (c * cli.Context ) error {
58
+ return trackInfo (c .Context , pkg , credsFile , c .Command .Name )
59
+ },
60
+ },
61
+ {
62
+ Name : "beta" ,
63
+ Aliases : []string {"b" },
64
+ Action : func (c * cli.Context ) error {
65
+ return trackInfo (c .Context , pkg , credsFile , c .Command .Name )
66
+ },
67
+ },
68
+ {
69
+ Name : "list" ,
70
+ Usage : "List all the tracks" ,
71
+ Aliases : []string {"l" },
72
+ Action : func (c * cli.Context ) error {
73
+ return listTracks (c .Context , pkg , credsFile )
74
+ },
75
+ },
48
76
},
49
77
},
50
78
},
@@ -56,21 +84,38 @@ func main() {
56
84
}
57
85
}
58
86
59
- func trackInfo (ctx context.Context , pkg string , credsFile string ) error {
87
+ func buildService (ctx context.Context , pkg string , credsFile string ) ( * androidpublisher. Service , string , error ) {
60
88
androidpublisherService , err := androidpublisher .NewService (ctx , option .WithCredentialsFile (credsFile ))
61
89
if err != nil {
62
- return err
90
+ return nil , "" , err
63
91
}
64
92
65
93
var appEdit androidpublisher.AppEdit
66
94
editCreate := androidpublisherService .Edits .Insert (pkg , & appEdit )
67
95
editCreateRsp , err := editCreate .Do ()
96
+ if err != nil {
97
+ return nil , "" , err
98
+ }
99
+ return androidpublisherService , editCreateRsp .Id , nil
100
+ }
101
+
102
+ func marshallAndPrint (v interface {}) error {
103
+ json , err := json .MarshalIndent (v , "" , " " )
104
+ if err != nil {
105
+ return err
106
+ }
107
+
108
+ fmt .Println (string (json ))
109
+ return nil
110
+ }
111
+
112
+ func trackInfo (ctx context.Context , pkg string , credsFile string , track string ) error {
113
+ service , editId , err := buildService (ctx , pkg , credsFile )
68
114
if err != nil {
69
115
return err
70
116
}
71
- editId := editCreateRsp .Id
72
117
73
- c := androidpublisherService .Edits .Tracks .Get (pkg , editId , "production" )
118
+ c := service .Edits .Tracks .Get (pkg , editId , track )
74
119
rsp , err := c .Do ()
75
120
if err != nil {
76
121
return err
@@ -79,13 +124,24 @@ func trackInfo(ctx context.Context, pkg string, credsFile string) error {
79
124
if len (rsp .Releases ) != 1 {
80
125
log .Fatal ("Should have received one response" )
81
126
}
82
- release := rsp .Releases [0 ]
127
+ return marshallAndPrint (rsp .Releases [0 ])
128
+ }
83
129
84
- json , err := json .MarshalIndent (release , "" , " " )
130
+ func listTracks (ctx context.Context , pkg string , credsFile string ) error {
131
+ service , editId , err := buildService (ctx , pkg , credsFile )
85
132
if err != nil {
86
133
return err
87
134
}
88
- fmt .Println (string (json ))
89
135
90
- return nil
136
+ c := service .Edits .Tracks .List (pkg , editId )
137
+ rsp , err := c .Do ()
138
+ if err != nil {
139
+ return err
140
+ }
141
+
142
+ trackNames := []string {}
143
+ for _ , track := range rsp .Tracks {
144
+ trackNames = append (trackNames , track .Track )
145
+ }
146
+ return marshallAndPrint (trackNames )
91
147
}
0 commit comments