Skip to content

Commit

Permalink
cmd/test: --explain now turns on verbose output
Browse files Browse the repository at this point in the history
Rather than requiring both `--explain` and `--verbose`/`-v` a user
just needs to pass in `--explain` and verbose output will be enabled.

Fixes: open-policy-agent#2069
Signed-off-by: Patrick East <east.patrick@gmail.com>
  • Loading branch information
patrick-east committed Apr 3, 2020
1 parent 3719797 commit 1e56328
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ The optional "gobench" output format conforms to the Go Benchmark Data Format.
if len(args) == 0 {
return fmt.Errorf("specify at least one file")
}

// If an --explain flag was set, turn on verbose output
if testParams.explain.IsSet() {
testParams.verbose = true
}

return nil
},

Expand Down
5 changes: 5 additions & 0 deletions util/enumflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func (f *EnumFlag) String() string {
return f.vs[f.i]
}

// IsSet will return true if the EnumFlag has been set.
func (f *EnumFlag) IsSet() bool {
return f.i != -1
}

// Set sets the enum value. If s is not a valid enum value, an error is
// returned.
func (f *EnumFlag) Set(s string) error {
Expand Down
8 changes: 8 additions & 0 deletions util/enumflag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func TestEnumFlag(t *testing.T) {
t.Fatalf("Expected default value to be foo but got: %v", flag.String())
}

if flag.IsSet() {
t.Fatalf("Expected IsSet() to be false")
}

if err := flag.Set("bar"); err != nil {
t.Fatalf("Unexpected error on set: %v", err)
}
Expand All @@ -25,6 +29,10 @@ func TestEnumFlag(t *testing.T) {
t.Fatalf("Expected value to be bar but got: %v", flag.String())
}

if !flag.IsSet() {
t.Fatalf("Expected IsSet() to be true")
}

if !strings.Contains(flag.Type(), "foo,bar,baz") {
t.Fatalf("Expected flag type to contain foo,bar,baz but got: %v", flag.Type())
}
Expand Down

0 comments on commit 1e56328

Please sign in to comment.