diff --git a/README.md b/README.md index 3e813d2..5faa572 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,16 @@ the executable is available in your PATH. ``` protoc --lint_out=. *.proto ``` +### Optional Checks +Optional checks are enabled but passing a comma separated list to the protoc +"parameter". Example: +``` +protoc --lint_out=sort_imports:. *.proto +``` + +Available optional checks: +* `sort_imports` - checks that imports are sorted in descending alphabetical +order. ## TODO * Write more tests diff --git a/main.go b/main.go index 529f165..b64ceb6 100644 --- a/main.go +++ b/main.go @@ -30,23 +30,21 @@ func main() { } ) + data, err := ioutil.ReadAll(os.Stdin) + panicOnError(err) + panicOnError(proto.Unmarshal(data, &generatorRequest)) + for _, p := range strings.Split(generatorRequest.GetParameter(), ",") { - switch p { + switch strings.TrimSpace(p) { + case "": + continue case SortImports: parameters.SortImports = true default: fmt.Fprintf(os.Stderr, "Unmatched parameter: %s", p) - totalErrors++ + os.Exit(1) } } - if totalErrors != 0 { - os.Exit(1) - } - - data, err := ioutil.ReadAll(os.Stdin) - panicOnError(err) - - panicOnError(proto.Unmarshal(data, &generatorRequest)) for _, file := range generatorRequest.GetProtoFile() { numErrors, err := linter.LintProtoFile(linter.Config{