MCPcopy
hub / github.com/golang/protobuf / CommandLineParameters

Method CommandLineParameters

protoc-gen-go/generator/generator.go:448–501  ·  view source on GitHub ↗

CommandLineParameters breaks the comma-separated list of key=value pairs in the parameter (a member of the request protobuf) into a key/value map. It then sets file name mappings defined by those entries.

(parameter string)

Source from the content-addressed store, hash-verified

446// in the parameter (a member of the request protobuf) into a key/value map.
447// It then sets file name mappings defined by those entries.
448func (g *Generator) CommandLineParameters(parameter string) {
449 g.Param = make(map[string]string)
450 for _, p := range strings.Split(parameter, ",") {
451 if i := strings.Index(p, "="); i < 0 {
452 g.Param[p] = ""
453 } else {
454 g.Param[p[0:i]] = p[i+1:]
455 }
456 }
457
458 g.ImportMap = make(map[string]string)
459 pluginList := "none" // Default list of plugin names to enable (empty means all).
460 for k, v := range g.Param {
461 switch k {
462 case "import_prefix":
463 g.ImportPrefix = v
464 case "import_path":
465 g.PackageImportPath = v
466 case "paths":
467 switch v {
468 case "import":
469 g.pathType = pathTypeImport
470 case "source_relative":
471 g.pathType = pathTypeSourceRelative
472 default:
473 g.Fail(fmt.Sprintf(`Unknown path type %q: want "import" or "source_relative".`, v))
474 }
475 case "plugins":
476 pluginList = v
477 case "annotate_code":
478 if v == "true" {
479 g.annotateCode = true
480 }
481 default:
482 if len(k) > 0 && k[0] == 'M' {
483 g.ImportMap[k[1:]] = v
484 }
485 }
486 }
487 if pluginList != "" {
488 // Amend the set of plugins.
489 enabled := make(map[string]bool)
490 for _, name := range strings.Split(pluginList, "+") {
491 enabled[name] = true
492 }
493 var nplugins []Plugin
494 for _, p := range plugins {
495 if enabled[p.Name()] {
496 nplugins = append(nplugins, p)
497 }
498 }
499 plugins = nplugins
500 }
501}
502
503// DefaultPackageName returns the package name printed for the object.
504// If its file is in a different package, it returns the package name we're using for this file, plus ".".

Callers

nothing calls this directly

Calls 2

FailMethod · 0.95
NameMethod · 0.65

Tested by

no test coverage detected