Skip to content

Commit a67d6ee

Browse files
committed
feat: add rule-plugin flag to CLI
Add a new flag to the api-linter CLI that allows specifying custom rule plugins. This is the first step toward supporting a plugin ecosystem for custom rules. Changes: - Added RulePluginPaths field to the cli struct to store plugin file paths - Added --rule-plugin flag that can be used multiple times for multiple plugins - Updated tests to verify the flag works correctly The flag follows the pattern of other path-related flags in the CLI: - Uses StringArrayVar to support multiple values - Consistent naming with other flags (kebab-case) - Clear documentation in the help text This is part of the implementation for issue googleapis#1485, enabling organization-specific custom rules through plugins rather than requiring users to fork the repository. References: - Issue discussion: googleapis#1485 - Go plugin docs: https://pkg.go.dev/plugin
1 parent f06c633 commit a67d6ee

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

cmd/api-linter/cli.go

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type cli struct {
4646
ListRulesFlag bool
4747
DebugFlag bool
4848
IgnoreCommentDisablesFlag bool
49+
RulePluginPaths []string
4950
}
5051

5152
// ExitForLintFailure indicates that a problem was found during linting.
@@ -67,6 +68,7 @@ func newCli(args []string) *cli {
6768
var listRulesFlag bool
6869
var debugFlag bool
6970
var ignoreCommentDisablesFlag bool
71+
var rulePluginFlag []string
7072

7173
// Register flag variables.
7274
fs := pflag.NewFlagSet("api-linter", pflag.ExitOnError)
@@ -82,6 +84,7 @@ func newCli(args []string) *cli {
8284
fs.BoolVar(&listRulesFlag, "list-rules", false, "Print the rules and exit. Honors the output-format flag.")
8385
fs.BoolVar(&debugFlag, "debug", false, "Run in debug mode. Panics will print stack.")
8486
fs.BoolVar(&ignoreCommentDisablesFlag, "ignore-comment-disables", false, "If set to true, disable comments will be ignored.\nThis is helpful when strict enforcement of AIPs are necessary and\nproto definitions should not be able to disable checks.")
87+
fs.StringArrayVar(&rulePluginFlag, "rule-plugin", nil, "The path to a custom rule plugin (.so file).\nMay be specified multiple times.")
8588

8689
// Parse flags.
8790
err := fs.Parse(args)
@@ -103,6 +106,7 @@ func newCli(args []string) *cli {
103106
ListRulesFlag: listRulesFlag,
104107
DebugFlag: debugFlag,
105108
IgnoreCommentDisablesFlag: ignoreCommentDisablesFlag,
109+
RulePluginPaths: rulePluginFlag,
106110
}
107111
}
108112

cmd/api-linter/cli_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ func TestNewCli(t *testing.T) {
4444
ProtoFiles: []string{},
4545
},
4646
},
47+
{
48+
name: "RulePlugins",
49+
inputArgs: []string{
50+
"--rule-plugin=plugin1.so",
51+
"--rule-plugin=plugin2.so",
52+
},
53+
wantCli: &cli{
54+
RulePluginPaths: []string{"plugin1.so", "plugin2.so"},
55+
ProtoFiles: []string{},
56+
},
57+
},
4758
}
4859
for _, test := range tests {
4960
t.Run(test.name, func(t *testing.T) {

0 commit comments

Comments
 (0)