@@ -11,10 +11,10 @@ import (
11
11
"text/tabwriter"
12
12
"time"
13
13
14
+ "github.com/juju/ansiterm"
14
15
"github.com/manifoldco/go-base32"
15
16
"github.com/manifoldco/go-base64"
16
17
"github.com/urfave/cli"
17
- "github.com/juju/ansiterm"
18
18
19
19
"github.com/manifoldco/torus-cli/api"
20
20
"github.com/manifoldco/torus-cli/apitypes"
@@ -282,7 +282,7 @@ func viewMachineCmd(ctx *cli.Context) error {
282
282
283
283
// Created profile
284
284
creator := profileMap [* machineBody .CreatedBy ]
285
- createdBy := creator .Body .Username + " (" + creator .Body .Name + ")"
285
+ createdBy := creator .Body .Name + " (" + ui . Faint ( creator .Body .Username ) + ")"
286
286
createdOn := machineBody .Created .Format (time .RFC3339 )
287
287
288
288
// Destroyed profile
@@ -291,7 +291,7 @@ func viewMachineCmd(ctx *cli.Context) error {
291
291
if machineBody .State == primitive .MachineDestroyedState {
292
292
destroyer := profileMap [* machineBody .DestroyedBy ]
293
293
destroyedOn = machineBody .Destroyed .Format (time .RFC3339 )
294
- destroyedBy = destroyer .Body .Username + " (" + destroyer .Body .Name + ")"
294
+ destroyedBy = destroyer .Body .Name + " (" + ui . Faint ( destroyer .Body .Name ) + ")"
295
295
}
296
296
297
297
// Membership info
@@ -309,29 +309,24 @@ func viewMachineCmd(ctx *cli.Context) error {
309
309
310
310
fmt .Println ("" )
311
311
w1 := tabwriter .NewWriter (os .Stdout , 0 , 0 , 8 , ' ' , 0 )
312
- fmt .Fprintf (w1 , "ID :\t %s\n " , machine .ID )
313
- fmt .Fprintf (w1 , "Name :\t %s\n " , machineBody .Name )
314
- fmt .Fprintf (w1 , "Role :\t %s\n " , roleOutput )
315
- fmt .Fprintf (w1 , "State :\t %s\n " , machineBody .State )
316
- fmt .Fprintf (w1 , "Created By :\t %s\n " , createdBy )
317
- fmt .Fprintf (w1 , "Created On :\t %s\n " , createdOn )
318
- fmt .Fprintf (w1 , "Destroyed By :\t %s\n " , destroyedBy )
319
- fmt .Fprintf (w1 , "Destroyed On :\t %s\n " , destroyedOn )
312
+ fmt .Fprintf (w1 , "%s :\t %s\n " , ui . Bold ( "ID" ) , machine .ID )
313
+ fmt .Fprintf (w1 , "%s :\t %s\n " , ui . Bold ( "Name" ), ui . Faint ( machineBody .Name ) )
314
+ fmt .Fprintf (w1 , "%s :\t %s\n " , ui . Bold ( "Role" ) , roleOutput )
315
+ fmt .Fprintf (w1 , "%s :\t %s\n " , ui . Bold ( "State" ), colorizeMachineState ( machineBody .State ) )
316
+ fmt .Fprintf (w1 , "%s :\t %s\n " , ui . Bold ( "Created By" ) , createdBy )
317
+ fmt .Fprintf (w1 , "%s :\t %s\n " , ui . Bold ( "Created On" ) , createdOn )
318
+ fmt .Fprintf (w1 , "%s :\t %s\n " , ui . Bold ( "Destroyed By" ) , destroyedBy )
319
+ fmt .Fprintf (w1 , "%s :\t %s\n " , ui . Bold ( "Destroyed On" ) , destroyedOn )
320
320
w1 .Flush ()
321
321
fmt .Println ("" )
322
322
323
323
w2 := ansiterm .NewTabWriter (os .Stdout , 2 , 0 , 3 , ' ' , 0 )
324
324
fmt .Fprintf (w2 , "%s\t %s\t %s\t %s\n " , ui .Bold ("Token ID" ), ui .Bold ("State" ), ui .Bold ("Created By" ), ui .Bold ("Created On" ))
325
325
for _ , token := range machineSegment .Tokens {
326
326
tokenID := token .Token .ID
327
- var state string
328
- if token .Token .Body .State == "active" {
329
- state = ui .Color (ui .Green , token .Token .Body .State )
330
- } else {
331
- state = ui .Color (ui .Red , token .Token .Body .State )
332
- }
327
+ state := colorizeMachineState (token .Token .Body .State )
333
328
creator := profileMap [* token .Token .Body .CreatedBy ]
334
- createdBy := creator .Body .Username + " (" + creator .Body .Name + ")"
329
+ createdBy := creator .Body .Name + " (" + ui . Faint ( creator .Body .Username ) + ")"
335
330
createdOn := token .Token .Body .Created .Format (time .RFC3339 )
336
331
fmt .Fprintf (w2 , "%s\t %s\t %s\t %s\n " , tokenID , state , createdBy , createdOn )
337
332
}
@@ -342,6 +337,17 @@ func viewMachineCmd(ctx *cli.Context) error {
342
337
return nil
343
338
}
344
339
340
+ func colorizeMachineState (state string ) string {
341
+ switch state {
342
+ case "active" :
343
+ return ui .Color (ui .Green , state )
344
+ case "destroyed" :
345
+ return ui .Color (ui .Red , state )
346
+ default :
347
+ return state
348
+ }
349
+ }
350
+
345
351
func listMachinesCmd (ctx * cli.Context ) error {
346
352
cfg , err := config .LoadConfig ()
347
353
if err != nil {
@@ -417,13 +423,9 @@ func listMachinesCmd(ctx *cli.Context) error {
417
423
roleName = role .Name
418
424
}
419
425
}
420
- var state string
421
- if m .State == "active" {
422
- state = ui .Color (ui .Green , m .State )
423
- } else {
424
- state = ui .Color (ui .Red , m .State )
425
- }
426
- fmt .Fprintf (w , "%s\t %s\t %s\t %s\t %s\n " , mID , m .Name , state , roleName , m .Created .Format (time .RFC3339 ))
426
+
427
+ state := colorizeMachineState (state )
428
+ fmt .Fprintf (w , "%s\t %s\t %s\t %s\t %s\n " , mID , ui .Faint (m .Name ), state , roleName , m .Created .Format (time .RFC3339 ))
427
429
}
428
430
w .Flush ()
429
431
fmt .Println ("" )
@@ -650,9 +652,9 @@ func createMachine(ctx *cli.Context) error {
650
652
w := tabwriter .NewWriter (os .Stdout , 2 , 0 , 1 , ' ' , 0 )
651
653
652
654
tokenID := machine .Tokens [0 ].Token .ID
653
- fmt .Fprintf (w , "Machine ID :\t %s\n " , machine .Machine .ID )
654
- fmt .Fprintf (w , "Machine Token ID :\t %s\n " , tokenID )
655
- fmt .Fprintf (w , "Machine Token Secret :\t %s\n " , tokenSecret )
655
+ fmt .Fprintf (w , "%s :\t %s\n " , ui . Bold ( "Machine ID" ) , machine .Machine .ID )
656
+ fmt .Fprintf (w , "%s :\t %s\n " , ui . Bold ( "Machine Token ID" ) , tokenID )
657
+ fmt .Fprintf (w , "%s :\t %s\n " , ui . Bold ( "Machine Token Secret" ) , tokenSecret )
656
658
657
659
w .Flush ()
658
660
hints .Display (hints .Allow , hints .Deny )
0 commit comments