MCPcopy Create free account
hub / github.com/bufbuild/buf / getNonProtoFilePath

Function getNonProtoFilePath

cmd/buf/internal/command/export/export.go:309–329  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

307//
308// e.g. README.foo.md, README.foo.2.md
309func 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}

Callers 1

runFunction · 0.85

Calls 4

ExtFunction · 0.92
OpaqueIDMethod · 0.65
FullNameMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…