@@ -7,23 +7,29 @@ import (
7
7
"strings"
8
8
"text/tabwriter"
9
9
10
- "github.com/valar/cli/config"
11
-
12
- "github.com/valar/cli/api"
13
-
14
10
"github.com/dustin/go-humanize"
15
11
"github.com/fatih/color"
16
12
"github.com/juju/ansiterm"
17
13
"github.com/spf13/cobra"
14
+ "github.com/valar/cli/api"
15
+ "github.com/valar/cli/config"
18
16
)
19
17
18
+ var buildService string
19
+
20
20
var buildCmd = & cobra.Command {
21
- Use : "builds [prefix]" ,
21
+ Use : "build [--service service]" ,
22
+ Short : "Manage the builds of a service" ,
23
+ Aliases : []string {"builds" , "b" },
24
+ }
25
+
26
+ var buildListCmd = & cobra.Command {
27
+ Use : "list [prefix]" ,
22
28
Short : "List builds of the service" ,
23
29
Args : cobra .MaximumNArgs (1 ),
24
30
Run : runAndHandle (func (cmd * cobra.Command , args []string ) error {
25
- cfg := & config.ServiceConfig {}
26
- if err := cfg . ReadFromFile ( functionConfiguration ); err != nil {
31
+ cfg , err := config .NewServiceConfigWithFallback ( functionConfiguration , & buildService , globalConfiguration )
32
+ if err != nil {
27
33
return err
28
34
}
29
35
client , err := globalConfiguration .APIClient ()
@@ -42,8 +48,8 @@ var buildAbortCmd = &cobra.Command{
42
48
Short : "Abort a scheduled or running build" ,
43
49
Args : cobra .MaximumNArgs (1 ),
44
50
Run : runAndHandle (func (cmd * cobra.Command , args []string ) error {
45
- cfg := & config.ServiceConfig {}
46
- if err := cfg . ReadFromFile ( functionConfiguration ); err != nil {
51
+ cfg , err := config .NewServiceConfigWithFallback ( functionConfiguration , & buildService , globalConfiguration )
52
+ if err != nil {
47
53
return err
48
54
}
49
55
client , err := globalConfiguration .APIClient ()
@@ -53,19 +59,19 @@ var buildAbortCmd = &cobra.Command{
53
59
if len (args ) < 1 {
54
60
args = append (args , "" )
55
61
}
56
- return client .AbortBuild (cfg .Project , cfg .Service , args [0 ])
62
+ return client .AbortBuild (cfg .Project () , cfg .Service () , args [0 ])
57
63
}),
58
64
}
59
65
60
66
var logsFollow = false
61
67
62
68
var buildLogsCmd = & cobra.Command {
63
- Use : "logs [task ]" ,
69
+ Use : "logs [buildid ]" ,
64
70
Short : "Show the build logs of the given task" ,
65
71
Args : cobra .MaximumNArgs (1 ),
66
72
Run : runAndHandle (func (cmd * cobra.Command , args []string ) error {
67
- cfg := & config.ServiceConfig {}
68
- if err := cfg . ReadFromFile ( functionConfiguration ); err != nil {
73
+ cfg , err := config .NewServiceConfigWithFallback ( functionConfiguration , & buildService , globalConfiguration )
74
+ if err != nil {
69
75
return err
70
76
}
71
77
client , err := globalConfiguration .APIClient ()
@@ -77,7 +83,7 @@ var buildLogsCmd = &cobra.Command{
77
83
if len (args ) > 0 {
78
84
prefix = args [0 ]
79
85
}
80
- builds , err := client .ListBuilds (cfg .Project , cfg .Service , prefix )
86
+ builds , err := client .ListBuilds (cfg .Project () , cfg .Service () , prefix )
81
87
if err != nil {
82
88
return err
83
89
}
@@ -88,19 +94,19 @@ var buildLogsCmd = &cobra.Command{
88
94
sort .Slice (builds , func (i , j int ) bool { return builds [i ].CreatedAt .After (builds [j ].CreatedAt ) })
89
95
latestBuildID := builds [0 ].ID
90
96
if logsFollow {
91
- return client .StreamBuildLogs (cfg .Project , cfg .Service , latestBuildID , os .Stdout )
97
+ return client .StreamBuildLogs (cfg .Project () , cfg .Service () , latestBuildID , os .Stdout )
92
98
}
93
- return client .ShowBuildLogs (cfg .Project , cfg .Service , latestBuildID , os .Stdout )
99
+ return client .ShowBuildLogs (cfg .Project () , cfg .Service () , latestBuildID , os .Stdout )
94
100
}),
95
101
}
96
102
97
- var inspectCmd = & cobra.Command {
103
+ var buildInspectCmd = & cobra.Command {
98
104
Use : "inspect [prefix]" ,
99
105
Short : "Inspect the first matched task with the given ID prefix" ,
100
106
Args : cobra .ExactArgs (1 ),
101
107
Run : runAndHandle (func (cmd * cobra.Command , args []string ) error {
102
- cfg := & config.ServiceConfig {}
103
- if err := cfg . ReadFromFile ( functionConfiguration ); err != nil {
108
+ cfg , err := config .NewServiceConfigWithFallback ( functionConfiguration , & buildService , globalConfiguration )
109
+ if err != nil {
104
110
return err
105
111
}
106
112
client , err := globalConfiguration .APIClient ()
@@ -111,13 +117,13 @@ var inspectCmd = &cobra.Command{
111
117
}),
112
118
}
113
119
114
- var statusCmd = & cobra.Command {
120
+ var buildStatusCmd = & cobra.Command {
115
121
Use : "status [buildid]" ,
116
122
Short : "Show the status of the given build" ,
117
123
Args : cobra .ExactArgs (1 ),
118
124
Run : runAndHandle (func (cmd * cobra.Command , args []string ) error {
119
- cfg := & config.ServiceConfig {}
120
- if err := cfg . ReadFromFile ( functionConfiguration ); err != nil {
125
+ cfg , err := config .NewServiceConfigWithFallback ( functionConfiguration , & buildService , globalConfiguration )
126
+ if err != nil {
121
127
return err
122
128
}
123
129
client , err := globalConfiguration .APIClient ()
@@ -129,8 +135,8 @@ var statusCmd = &cobra.Command{
129
135
}),
130
136
}
131
137
132
- func listBuilds (client * api.Client , cfg * config.ServiceConfig , id string ) error {
133
- builds , err := client .ListBuilds (cfg .Project , cfg .Service , id )
138
+ func listBuilds (client * api.Client , cfg config.ServiceConfig , id string ) error {
139
+ builds , err := client .ListBuilds (cfg .Project () , cfg .Service () , id )
134
140
if err != nil {
135
141
return err
136
142
}
@@ -151,8 +157,8 @@ func listBuilds(client *api.Client, cfg *config.ServiceConfig, id string) error
151
157
return nil
152
158
}
153
159
154
- func showBuildStatusAndExit (client * api.Client , cfg * config.ServiceConfig , id string ) error {
155
- build , err := client .InspectBuild (cfg .Project , cfg .Service , id )
160
+ func showBuildStatusAndExit (client * api.Client , cfg config.ServiceConfig , id string ) error {
161
+ build , err := client .InspectBuild (cfg .Project () , cfg .Service () , id )
156
162
if err != nil {
157
163
return err
158
164
}
@@ -161,8 +167,8 @@ func showBuildStatusAndExit(client *api.Client, cfg *config.ServiceConfig, id st
161
167
return nil
162
168
}
163
169
164
- func inspectBuild (client * api.Client , cfg * config.ServiceConfig , id string ) error {
165
- build , err := client .InspectBuild (cfg .Project , cfg .Service , id )
170
+ func inspectBuild (client * api.Client , cfg config.ServiceConfig , id string ) error {
171
+ build , err := client .InspectBuild (cfg .Project () , cfg .Service () , id )
166
172
if err != nil {
167
173
return err
168
174
}
@@ -180,13 +186,13 @@ func inspectBuild(client *api.Client, cfg *config.ServiceConfig, id string) erro
180
186
return nil
181
187
}
182
188
183
- func deployBuild (client * api.Client , cfg * config.ServiceConfig , id string ) error {
189
+ func deployBuild (client * api.Client , cfg config.ServiceConfig , id string ) error {
184
190
var deployReq api.DeployRequest
185
191
deployReq .Build = id
186
- for _ , kv := range cfg .Deployment .Environment {
192
+ for _ , kv := range cfg .Deployment () .Environment {
187
193
deployReq .Environment = append (deployReq .Environment , api .KVPair (kv ))
188
194
}
189
- deployment , err := client .SubmitDeploy (cfg .Project , cfg .Service , & deployReq )
195
+ deployment , err := client .SubmitDeploy (cfg .Project () , cfg .Service () , & deployReq )
190
196
if err != nil {
191
197
return err
192
198
}
@@ -219,10 +225,8 @@ func colorize(status string) string {
219
225
}
220
226
221
227
func initBuildsCmd () {
222
- buildLogsCmd .PersistentFlags ().BoolVarP (& logsFollow , "follow" , "f" , false , "follow the logs" )
223
- buildCmd .AddCommand (inspectCmd )
224
- buildCmd .AddCommand (buildLogsCmd )
225
- buildCmd .AddCommand (buildAbortCmd )
226
- buildCmd .AddCommand (statusCmd )
228
+ buildCmd .PersistentFlags ().StringVarP (& buildService , "service" , "s" , "" , "The service to inspect for builds" )
229
+ buildLogsCmd .PersistentFlags ().BoolVarP (& logsFollow , "follow" , "f" , false , "Follow the logs" )
230
+ buildCmd .AddCommand (buildListCmd , buildInspectCmd , buildLogsCmd , buildAbortCmd , buildStatusCmd )
227
231
rootCmd .AddCommand (buildCmd )
228
232
}
0 commit comments