Skip to content

Commit

Permalink
Restored condition to check for number of parameters above expected n…
Browse files Browse the repository at this point in the history
…umber (now 4). Also changed for loop to be more idiomatic.
  • Loading branch information
willchang committed Aug 19, 2022
1 parent bb0c8ee commit d0ef57b
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,38 +163,35 @@ func ParseOptions(req *plugin_go.CodeGeneratorRequest) (*PluginOptions, error) {
}

parts := strings.Split(params, ",")
if len(parts) < 2 {
if len(parts) < 2 || len(parts) > 4 {
return nil, fmt.Errorf("Invalid parameter: %s", params)
}

options.TemplateFile = parts[0]
options.OutputFile = path.Base(parts[1])

if len(parts) > 2 {
extraOptions := parts[2:]

for i := 0; i < len(extraOptions); i++ {
switch i {
case 0: // Third option
switch extraOptions[i] {
case "source_relative":
options.SourceRelative = true
case "default":
options.SourceRelative = false
default:
return nil, fmt.Errorf("Invalid parameter: %s", params)
}
case 1: // Fourth option
switch extraOptions[i] {
case "separate_files":
options.SeparateFiles = true
case "default":
options.SeparateFiles = false
default:
return nil, fmt.Errorf("Invalid parameter: %s", params)
}
extraOptions := parts[2:]

for i := range extraOptions {
switch i {
case 0: // Third option
switch extraOptions[i] {
case "source_relative":
options.SourceRelative = true
case "default":
options.SourceRelative = false
default:
return nil, fmt.Errorf("Invalid parameter: %s", params)
}
case 1: // Fourth option
switch extraOptions[i] {
case "separate_files":
options.SeparateFiles = true
case "default":
options.SeparateFiles = false
default:
return nil, fmt.Errorf("Invalid parameter: %s", params)
}

}
}

Expand Down

0 comments on commit d0ef57b

Please sign in to comment.