Skip to content

Commit

Permalink
cmd/jv: simplify output arg validation
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Aug 29, 2023
1 parent e0c304c commit b9a55db
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions cmd/jv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,18 @@ func main() {
compiler.AssertFormat = *assertFormat
compiler.AssertContent = *assertContent

var validOutput bool
for _, out := range append(validOutputs, "") {
if *output == out {
validOutput = true
break
if *output != "" {
valid := false
for _, out := range validOutputs {
if *output == out {
valid = true
break
}
}
if !valid {
fmt.Fprintln(os.Stderr, "output must be one of", strings.Join(validOutputs, ", "))
os.Exit(2)
}
}
if !validOutput {
fmt.Fprintln(os.Stderr, "output must be one of", strings.Join(validOutputs, ", "))
os.Exit(2)
}

schema, err := compiler.Compile(flag.Arg(0))
Expand Down

0 comments on commit b9a55db

Please sign in to comment.