This is a helper function that returns the path non-proto source files should be written to if the --all flag has been set. This sets an identifier for the module using the module name, [bufparse.FullName.Name()] if available, and if not, we use [module.OpaqueID()]. e.g. README.foo.md, README.bar.
( path string, module bufmodule.Module, seenModuleNamesForPath map[string]int, )
| 307 | // |
| 308 | // e.g. README.foo.md, README.foo.2.md |
| 309 | func getNonProtoFilePath( |
| 310 | path string, |
| 311 | module bufmodule.Module, |
| 312 | seenModuleNamesForPath map[string]int, |
| 313 | ) string { |
| 314 | moduleIdentifier := module.OpaqueID() |
| 315 | if module.FullName() != nil { |
| 316 | moduleIdentifier = module.FullName().Name() |
| 317 | seenModuleNamesForPath[module.FullName().Name()]++ |
| 318 | count := seenModuleNamesForPath[module.FullName().Name()] |
| 319 | if count > 1 { |
| 320 | moduleIdentifier = fmt.Sprintf("%s.%d", module.FullName().Name(), count) |
| 321 | } |
| 322 | } |
| 323 | return fmt.Sprintf( |
| 324 | "%s.%s%s", |
| 325 | strings.TrimSuffix(path, normalpath.Ext(path)), |
| 326 | moduleIdentifier, |
| 327 | normalpath.Ext(path), |
| 328 | ) |
| 329 | } |