@@ -59,6 +59,11 @@ func main() {
5959 Usage : "Name of the service" ,
6060 Value : "" ,
6161 },
62+ cli.StringFlag {
63+ Name : "timeout, t" ,
64+ Usage : "Timeout duration (optional)" ,
65+ Value : "" ,
66+ },
6267 },
6368 },
6469 {
@@ -77,6 +82,11 @@ func main() {
7782 Usage : "Name of the service" ,
7883 Value : "" ,
7984 },
85+ cli.StringFlag {
86+ Name : "timeout, t" ,
87+ Usage : "Timeout duration (optional)" ,
88+ Value : "" ,
89+ },
8090 },
8191 },
8292 {
@@ -95,6 +105,11 @@ func main() {
95105 Usage : "Name of the service" ,
96106 Value : "" ,
97107 },
108+ cli.StringFlag {
109+ Name : "timeout, t" ,
110+ Usage : "Timeout duration (optional)" ,
111+ Value : "" ,
112+ },
98113 },
99114 },
100115 {
@@ -113,6 +128,11 @@ func main() {
113128 Usage : "Name of the service" ,
114129 Value : "" ,
115130 },
131+ cli.StringFlag {
132+ Name : "timeout, t" ,
133+ Usage : "Timeout duration (optional)" ,
134+ Value : "" ,
135+ },
116136 },
117137 },
118138 {
@@ -165,12 +185,34 @@ func actionDeploy(c *cli.Context) error {
165185 }
166186 }
167187
188+ var timeout time.Duration
189+ timeoutStr := c .String ("timeout" )
190+ if len (timeoutStr ) > 0 {
191+ timeout , err = time .ParseDuration (timeoutStr )
192+ if err != nil {
193+ fmt .Println ("Illegal timeout parameter" )
194+ os .Exit (1 )
195+ } else if timeout < 0 {
196+ fmt .Println ("Timeout duration must be positive" )
197+ os .Exit (1 )
198+ }
199+ }
200+
168201 spawnClient , err := spawnclient .New (c .GlobalString ("router" ), entity )
169202 if err != nil {
170203 fmt .Printf ("Could not create spawnpoint client: %s\n " , err )
171204 }
172205
173- logChan , errChan := spawnClient .Tail (context .Background (), svcName , spawnpointURI )
206+ var ctx context.Context
207+ var cancel context.CancelFunc
208+ if timeout == 0 {
209+ ctx = context .Background ()
210+ } else {
211+ ctx , cancel = context .WithTimeout (context .Background (), timeout )
212+ defer cancel ()
213+ }
214+ logChan , errChan := spawnClient .Tail (ctx , svcName , spawnpointURI )
215+
174216 // Check if an error has already occurred
175217 select {
176218 case err = <- errChan :
@@ -184,7 +226,11 @@ func actionDeploy(c *cli.Context) error {
184226 os .Exit (1 )
185227 }
186228
187- fmt .Println ("Tailing service logs. Press CTRL-c to exit..." )
229+ if timeout == 0 {
230+ fmt .Println ("Tailing service logs. Press CTRL-c to exit..." )
231+ } else {
232+ fmt .Printf ("Tailing service logs for %s. Press CTRL-c to exit early...\n " , timeout .String ())
233+ }
188234 for msg := range logChan {
189235 fmt .Println (strings .TrimSpace (msg .Contents ))
190236 }
@@ -228,12 +274,35 @@ func manipulateService(c *cli.Context, command string) error {
228274 os .Exit (1 )
229275 }
230276
277+ var timeout time.Duration
278+ var err error
279+ timeoutStr := c .String ("timeout" )
280+ if len (timeoutStr ) > 0 {
281+ timeout , err = time .ParseDuration (timeoutStr )
282+ if err != nil {
283+ fmt .Println ("Illegal timeout parameter" )
284+ os .Exit (1 )
285+ } else if timeout < 0 {
286+ fmt .Println ("Timeout duration must be positive" )
287+ os .Exit (1 )
288+ }
289+ }
290+
231291 spawnClient , err := spawnclient .New (c .GlobalString ("router" ), entity )
232292 if err != nil {
233293 fmt .Printf ("Could not create spawnpoint client: %s\n " , err )
234294 }
235295
236- logChan , errChan := spawnClient .Tail (context .Background (), svcName , spawnpointURI )
296+ var ctx context.Context
297+ var cancel context.CancelFunc
298+ if timeout == 0 {
299+ ctx = context .Background ()
300+ } else {
301+ ctx , cancel = context .WithTimeout (context .Background (), timeout )
302+ defer cancel ()
303+ }
304+ logChan , errChan := spawnClient .Tail (ctx , svcName , spawnpointURI )
305+
237306 // Check if an error has already occurred
238307 select {
239308 case err = <- errChan :
@@ -260,7 +329,11 @@ func manipulateService(c *cli.Context, command string) error {
260329 os .Exit (1 )
261330 }
262331
263- fmt .Println ("Tailing service logs. Press CTRL-c to exit..." )
332+ if timeout == 0 {
333+ fmt .Println ("Tailing service logs. Press CTRL-c to exit..." )
334+ } else {
335+ fmt .Printf ("Tailing service logs for %s. Press CTRL-c to exit early...\n " , timeout .String ())
336+ }
264337 for msg := range logChan {
265338 fmt .Println (strings .TrimSpace (msg .Contents ))
266339 }
@@ -301,7 +374,7 @@ func actionScan(c *cli.Context) error {
301374
302375 if len (heartbeats ) == 1 {
303376 // Guaranteed to iterate once
304- for uri , _ := range heartbeats {
377+ for uri := range heartbeats {
305378 daemonHb , svcHbs , err := spawnClient .Inspect (uri )
306379 if err != nil {
307380 fmt .Printf ("Inspect failed: %s\n " , err )
0 commit comments