Repository: googleapis/api-linter
Pull request #327 (2019-11-09 02:50:22)

Rename descriptor set flag.
issue #317 


Patch:
diff --git a/cmd/api-linter/cli.go b/cmd/api-linter/cli.go
index 724b626..a12b44d 100644
--- a/cmd/api-linter/cli.go
+++ b/cmd/api-linter/cli.go
@@ -38,7 +38,7 @@ type cli struct {
 	OutputPath       string
 	ProtoImportPaths []string
 	ProtoFiles       []string
-	ProtoDescPath    string
+	ProtoDescPath    []string
 	EnabledRules     []string
 	DisabledRules    []string
 }
@@ -49,7 +49,7 @@ func newCli(args []string) *cli {
 	var fmtFlag string
 	var outFlag string
 	var protoImportFlag []string
-	var protoDescFlag string
+	var protoDescFlag []string
 	var ruleEnableFlag []string
 	var ruleDisableFlag []string
 
@@ -59,7 +59,7 @@ func newCli(args []string) *cli {
 	fs.StringVar(&fmtFlag, "output-format", "", "The format of the linting results.\nSupported formats include \"yaml\", \"json\" and \"summary\" table.\nYAML is the default.")
 	fs.StringVarP(&outFlag, "output-path", "o", "", "The output file path.\nIf not given, the linting results will be printed out to STDOUT.")
 	fs.StringArrayVarP(&protoImportFlag, "proto-path", "I", nil, "The folder for searching proto imports.\nMay be specified multiple times; directories will be searched in order.\nThe current working directory is always used.")
-	fs.StringVar(&protoDescFlag, "proto-descriptor-set", "", "A delimited (':') list of files each containing a FileDescriptorSet for searching proto imports.")
+	fs.StringArrayVar(&protoDescFlag, "descriptor-set-in", nil, "The file containing a FileDescriptorSet for searching proto imports.\nMay be specified multiple times.")
 	fs.StringArrayVar(&ruleEnableFlag, "enable-rule", nil, "Enable a rule with the given name.\nMay be specified multiple times.")
 	fs.StringArrayVar(&ruleDisableFlag, "disable-rule", nil, "Disable a rule with the given name.\nMay be specified multiple times.")
 
@@ -100,18 +100,15 @@ func (c *cli) lint(rules lint.RuleRegistry, configs lint.Configs) error {
 		DisabledRules: c.DisabledRules,
 	})
 	// Prepare proto import lookup.
-	var lookupImport func(string) (*desc.FileDescriptor, error)
-	if c.ProtoDescPath != "" {
-		fs, err := loadFileDescriptors(strings.Split(c.ProtoDescPath, ":")...)
-		if err != nil {
-			return err
-		}
-		lookupImport = func(name string) (*desc.FileDescriptor, error) {
-			if f, found := fs[name]; found {
-				return f, nil
-			}
-			return nil, fmt.Errorf("%q is not found", name)
+	fs, err := loadFileDescriptors(c.ProtoDescPath...)
+	if err != nil {
+		return err
+	}
+	lookupImport := func(name string) (*desc.FileDescriptor, error) {
+		if f, found := fs[name]; found {
+			return f, nil
 		}
+		return nil, fmt.Errorf("%q is not found", name)
 	}
 	var errorsWithPos []protoparse.ErrorWithPos
 	var lock sync.Mutex
diff --git a/docs/index.md b/docs/index.md
index 6d9de80..f5b503b 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -49,20 +49,21 @@ To see the help message, run `api-linter -h`
 
 ```text
 Usage of api-linter:
-      --config string                 The linter config file.
-      --disable-rule stringArray      Disable a rule with the given name.
-                                      May be specified multiple times.
-      --enable-rule stringArray       Enable a rule with the given name.
-                                      May be specified multiple times.
-      --output-format string          The format of the linting results.
-                                      Supported formats include "yaml", "json" and "summary" table.
-                                      YAML is the default.
-  -o, --output-path string            The output file path.
-                                      If not given, the linting results will be printed out to STDOUT.
-      --proto-descriptor-set string   A delimited (':') list of files each containing a FileDescriptorSet for searching proto imports.
-  -I, --proto-path stringArray        The folder for searching proto imports.
-                                      May be specified multiple times; directories will be searched in order.
-                                      The current working directory is always used.
+      --config string                   The linter config file.
+      --descriptor-set-in stringArray   The file containing a FileDescriptorSet for searching proto imports.
+                                        May be specified multiple times.
+      --disable-rule stringArray        Disable a rule with the given name.
+                                        May be specified multiple times.
+      --enable-rule stringArray         Enable a rule with the given name.
+                                        May be specified multiple times.
+      --output-format string            The format of the linting results.
+                                        Supported formats include "yaml", "json" and "summary" table.
+                                        YAML is the default.
+  -o, --output-path string              The output file path.
+                                        If not given, the linting results will be printed out to STDOUT.
+  -I, --proto-path stringArray          The folder for searching proto imports.
+                                        May be specified multiple times; directories will be searched in order.
+                                        The current working directory is always used.
 ```
 
 ## License


Test patch:
diff --git a/cmd/api-linter/cli_test.go b/cmd/api-linter/cli_test.go
index c78ae31..1efea5c 100644
--- a/cmd/api-linter/cli_test.go
+++ b/cmd/api-linter/cli_test.go
@@ -1,7 +1,6 @@
 package main
 
 import (
-	"strings"
 	"testing"
 
 	"github.com/google/go-cmp/cmp"
@@ -14,13 +13,23 @@ func TestNewCli(t *testing.T) {
 		wantCli   *cli
 	}{
 		{
-			name:      "AllFlags",
-			inputArgs: strings.Split("--config=config --output-format=json -o=out --proto-descriptor-set=proto_desc -I=proto_path_a -I=proto_path_b a.proto b.proto", " "),
+			name: "AllFlags",
+			inputArgs: []string{
+				"--config=config",
+				"--output-format=json",
+				"-o=out",
+				"--descriptor-set-in=proto_desc1",
+				"--descriptor-set-in=proto_desc2",
+				"--proto-path=proto_path_a",
+				"-I=proto_path_b",
+				"a.proto",
+				"b.proto",
+			},
 			wantCli: &cli{
 				ConfigPath:       "config",
 				OutputPath:       "out",
 				FormatType:       "json",
-				ProtoDescPath:    "proto_desc",
+				ProtoDescPath:    []string{"proto_desc1", "proto_desc2"},
 				ProtoImportPaths: []string{"proto_path_a", "proto_path_b", "."},
 				ProtoFiles:       []string{"a.proto", "b.proto"},
 			},
diff --git a/cmd/api-linter/integration_test.go b/cmd/api-linter/integration_test.go
index cf805c6..4e07cd9 100644
--- a/cmd/api-linter/integration_test.go
+++ b/cmd/api-linter/integration_test.go
@@ -155,7 +155,7 @@ func runLinter(t *testing.T, protoContent, configContent string) string {
 	// Add the temp dir to the proto paths.
 	args = append(args, fmt.Sprintf("-I=%s", tempDir))
 	// Add a flag for the file descriptor set.
-	args = append(args, "--proto-descriptor-set=internal/testdata/dummy.protoset")
+	args = append(args, "--descriptor-set-in=internal/testdata/dummy.protoset")
 	// Write the proto file.
 	protoFileName := "test.proto"
 	protoFilePath := filepath.Join(tempDir, protoFileName)