@@ -11,6 +11,7 @@ import (
11
11
"text/tabwriter"
12
12
13
13
"github.com/urfave/cli"
14
+ "github.com/juju/ansiterm"
14
15
15
16
"github.com/manifoldco/torus-cli/api"
16
17
"github.com/manifoldco/torus-cli/apitypes"
@@ -20,6 +21,7 @@ import (
20
21
"github.com/manifoldco/torus-cli/identity"
21
22
"github.com/manifoldco/torus-cli/pathexp"
22
23
"github.com/manifoldco/torus-cli/primitive"
24
+ "github.com/manifoldco/torus-cli/ui"
23
25
"github.com/manifoldco/torus-cli/validate"
24
26
)
25
27
@@ -33,7 +35,7 @@ func init() {
33
35
Name : "list" ,
34
36
Usage : "List all policies for an organization" ,
35
37
Flags : []cli.Flag {
36
- orgFlag ("The org to show policies for" , true ),
38
+ orgFlag ("The org to show policies for" , false ),
37
39
},
38
40
Action : chain (
39
41
ensureDaemon , ensureSession , loadDirPrefs , loadPrefDefaults ,
@@ -45,7 +47,7 @@ func init() {
45
47
Usage : "Display the contents of a policy" ,
46
48
ArgsUsage : "<policy>" ,
47
49
Flags : []cli.Flag {
48
- orgFlag ("The org the policy belongs to" , true ),
50
+ orgFlag ("The org the policy belongs to" , false ),
49
51
},
50
52
Action : chain (
51
53
ensureDaemon , ensureSession , loadDirPrefs , loadPrefDefaults ,
@@ -332,14 +334,9 @@ func listPoliciesCmd(ctx *cli.Context) error {
332
334
client := api .NewClient (cfg )
333
335
c := context .Background ()
334
336
335
- // Look up the target org
336
- var org * envelope.Org
337
- org , err = client .Orgs .GetByName (c , ctx .String ("org" ))
337
+ org , err := getOrgWithPrompt (client , c , ctx .String ("org" ))
338
338
if err != nil {
339
- return errs .NewErrorExitError (policyListFailed , err )
340
- }
341
- if org == nil {
342
- return errs .NewExitError ("Org not found." )
339
+ return err
343
340
}
344
341
345
342
var getAttachments , display sync.WaitGroup
@@ -400,9 +397,8 @@ func listPoliciesCmd(ctx *cli.Context) error {
400
397
401
398
display .Wait ()
402
399
fmt .Println ("" )
403
- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 4 , ' ' , 0 )
404
- fmt .Fprintln (w , "POLICY NAME\t TYPE\t ATTACHED TO" )
405
- fmt .Fprintln (w , " \t \t " )
400
+ w := ansiterm .NewTabWriter (os .Stdout , 0 , 0 , 4 , ' ' , 0 )
401
+ fmt .Fprintf (w , "%s\t %s\t %s\n " , ui .Bold ("Policy Name" ), ui .Bold ("Type" ), ui .Bold ("Attached To" ))
406
402
for _ , name := range sortedNames {
407
403
teamNames := ""
408
404
policy := policiesByName [name ]
@@ -441,12 +437,9 @@ func viewPolicyCmd(ctx *cli.Context) error {
441
437
client := api .NewClient (cfg )
442
438
c := context .Background ()
443
439
444
- org , err := client . Orgs . GetByName ( c , ctx .String ("org" ))
440
+ org , err := getOrgWithPrompt ( client , c , ctx .String ("org" ))
445
441
if err != nil {
446
- return errs .NewErrorExitError ("Unable to lookup org." , err )
447
- }
448
- if org == nil {
449
- return errs .NewExitError ("Org not found." )
442
+ return err
450
443
}
451
444
452
445
policies , err := client .Policies .List (c , org .ID , policyName )
@@ -463,8 +456,8 @@ func viewPolicyCmd(ctx *cli.Context) error {
463
456
464
457
w := tabwriter .NewWriter (os .Stdout , 2 , 0 , 1 , ' ' , 0 )
465
458
466
- fmt .Fprintf (w , "Name: \t %s\n " , p .Name )
467
- fmt .Fprintf (w , "Description: \t %s\n " , p .Description )
459
+ fmt .Fprintf (w , "%s \t %s\n " , ui . Bold ( "Name:" ) , p .Name )
460
+ fmt .Fprintf (w , "%s \t %s\n " , ui . Bold ( "Description:" ) , p .Description )
468
461
fmt .Fprintln (w , "" )
469
462
w .Flush ()
470
463
0 commit comments