Permalink
Browse files

add extra-plugin-flag flag

Signed-off-by: Peter Edge <peter.edge@gmail.com>
  • Loading branch information...
peter-edge committed Aug 9, 2016
1 parent 615430c commit fbf2a638183453c884830599dbe9a32317d808da
Showing with 114 additions and 64 deletions.
  1. +6 −0 cmd/protoeasy/main.go
  2. +19 −0 plugins.go
  3. +22 −0 plugins_test.go
  4. +66 −64 protoeasy.pb.go
  5. +1 −0 protoeasy.proto
View
@@ -126,6 +126,12 @@ func bindCompileOptions(flagSet *pflag.FlagSet, compileOptions *protoeasy.Compil
"",
"The directory we are within, must be relative. This directory will be the base of the include path.",
)
flagSet.StringSliceVar(
&compileOptions.ExtraPluginFlag,
"extra-plugin-flag",
[]string{},
"Extra _out flags to pass to protoc. For example, if you have a plugin named foo where you would normally do --foo_out=/path/to/out, you do --extra-plugin-flag=foo. If you would have parameters to foo such as --foo_out=something=one,something_else=two:/path/to/out, you do --extra-plugin-flag=foo=something=one,something_else=two.",
)
flagSet.BoolVar(
&compileOptions.Cpp,
View
@@ -39,6 +39,9 @@ func getPlugins(compileOptions *CompileOptions) []plugin {
if compileOptions.DescriptorSet {
plugins = append(plugins, newDescriptorSetPlugin(compileOptions))
}
for _, extraPluginFlag := range compileOptions.ExtraPluginFlag {
plugins = append(plugins, newExtraPlugin(extraPluginFlag))
}
return plugins
}
@@ -247,6 +250,22 @@ func (p *basePlugin) Flags(protoSpec *protoSpec, relDirPath string, outDirPath s
return []string{fmt.Sprintf("--%s_out=%s", p.name, outDirPath)}, nil
}
type extraPlugin struct {
flagString string
}
func newExtraPlugin(flagString string) *extraPlugin {
return &extraPlugin{flagString}
}
func (p *extraPlugin) Flags(protoSpec *protoSpec, relDirPath string, outDirPath string) ([]string, error) {
split := strings.SplitN(p.flagString, "=", 2)
if len(split) == 1 {
return []string{fmt.Sprintf("--%s_out=%s", split[0], outDirPath)}, nil
}
return []string{fmt.Sprintf("--%s_out=%s:%s", split[0], split[1], outDirPath)}, nil
}
type grpcPlugin struct {
*basePlugin
grpcName string
View
@@ -0,0 +1,22 @@
package protoeasy
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func TestExtraPlugin(t *testing.T) {
testExtraPlugin(t, "foo", "--foo_out=")
testExtraPlugin(t, "foo=hello=one", "--foo_out=hello=one:")
testExtraPlugin(t, "foo=hello=one,woot=two", "--foo_out=hello=one,woot=two:")
}
func testExtraPlugin(t *testing.T, flagString string, flagMinusOutDirPath string) {
plugin := newExtraPlugin(flagString)
flags, err := plugin.Flags(nil, "", "/path/to/out")
require.NoError(t, err)
require.Len(t, flags, 1)
require.Equal(t, fmt.Sprintf("%s/path/to/out", flagMinusOutDirPath), flags[0])
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -24,6 +24,7 @@ message CompileOptions {
bool no_default_includes = 3;
repeated string exclude_pattern = 4;
string rel_context = 5;
repeated string extra_plugin_flag = 6;
bool cpp = 20;
string cpp_rel_out = 21;

0 comments on commit fbf2a63

Please sign in to comment.