Ejemplo n.º 1
0
Archivo: main.go Proyecto: sr/protoeasy
func optionsToCompileOptions(options *options, compileOptions *protoeasy.CompileOptions) error {
	if strings.ToLower(options.GoPluginType) == "none" {
		return fmt.Errorf("invalid value for --go-protoc-plugin: %s", options.GoPluginType)
	}
	goPluginType, err := protoeasy.GoPluginTypeSimpleValueOf(options.GoPluginType)
	if err != nil {
		return err
	}
	compileOptions.GoPluginType = goPluginType
	// TODO(pedge): duplicated logic in goPlugin struct
	if goPluginType != protoeasy.GoPluginType_GO_PLUGIN_TYPE_GO {
		compileOptions.GoNoDefaultModifiers = true
	}
	modifiers := make(map[string]string)
	for _, modifierString := range options.GoModifiers {
		split := strings.SplitN(modifierString, "=", 2)
		if len(split) != 2 {
			return fmt.Errorf("invalid valid for --go-modifier: %s", modifierString)
		}
		modifiers[split[0]] = split[1]
	}
	compileOptions.GoModifiers = modifiers
	// TODO(pedge): this should not be in this function
	// TODO(pedge): duplicated logic in goPlugin struct
	if compileOptions.NoDefaultIncludes {
		compileOptions.GoNoDefaultModifiers = true
	}
	return nil
}
Ejemplo n.º 2
0
func optionsToCompileOptions(options *options, compileOptions *protoeasy.CompileOptions) error {
	if strings.ToLower(options.GoPluginType) == "none" {
		return fmt.Errorf("invalid value for --go-plugin: %s", options.GoPluginType)
	}
	goPluginType, err := protoeasy.GoPluginTypeSimpleValueOf(options.GoPluginType)
	if err != nil {
		return err
	}
	compileOptions.GoPluginType = goPluginType
	goModifiers, err := getModifiers(options.GoModifiers)
	if err != nil {
		return err
	}
	compileOptions.GoModifiers = goModifiers
	if strings.ToLower(options.GogoPluginType) == "none" {
		return fmt.Errorf("invalid value for --gogo-plugin: %s", options.GogoPluginType)
	}
	gogoPluginType, err := protoeasy.GogoPluginTypeSimpleValueOf(options.GogoPluginType)
	if err != nil {
		return err
	}
	compileOptions.GogoPluginType = gogoPluginType
	gogoModifiers, err := getModifiers(options.GogoModifiers)
	if err != nil {
		return err
	}
	compileOptions.GogoModifiers = gogoModifiers
	// TODO(pedge): this should not be in this function
	// TODO(pedge): duplicated logic in goPlugin struct
	if compileOptions.NoDefaultIncludes {
		compileOptions.GoNoDefaultModifiers = true
		compileOptions.GogoNoDefaultModifiers = true
	}
	return nil
}