1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-12 22:07:47 +02:00

Runtime name should be base folder outside repos (#1598)

This commit is contained in:
Janos Dobronszki
2020-04-30 18:20:51 +02:00
committed by GitHub
parent 46d09ec2bc
commit fccab8ad27
2 changed files with 64 additions and 11 deletions

View File

@ -274,20 +274,35 @@ func ParseSource(source string) (*Source, error) {
}
// ParseSourceLocal detects and handles local pathes too
// workdir should be used only from the CLI @todo better interface for this function
func ParseSourceLocal(workDir, source string) (*Source, error) {
// workdir should be used only from the CLI @todo better interface for this function.
// PathExistsFunc exists only for testing purposes, to make the function side effect free.
func ParseSourceLocal(workDir, source string, pathExistsFunc ...func(path string) (bool, error)) (*Source, error) {
var pexists func(string) (bool, error)
if len(pathExistsFunc) == 0 {
pexists = pathExists
} else {
pexists = pathExistsFunc[0]
}
var localFullPath string
if len(workDir) > 0 {
localFullPath = filepath.Join(workDir, source)
} else {
localFullPath = source
}
if exists, err := pathExists(localFullPath); err == nil && exists {
if exists, err := pexists(localFullPath); err == nil && exists {
localRepoRoot, err := GetRepoRoot(localFullPath)
if err != nil {
return nil, err
}
folder := strings.ReplaceAll(localFullPath, localRepoRoot+string(filepath.Separator), "")
var folder string
// If the local repo root is a top level folder, we are not in a git repo.
// In this case, we should take the last folder as folder name.
if localRepoRoot == "" {
folder = filepath.Base(localFullPath)
} else {
folder = strings.ReplaceAll(localFullPath, localRepoRoot+string(filepath.Separator), "")
}
return &Source{
Local: true,
Folder: folder,