|
|
@ -66,15 +66,15 @@ func run(cmd *cobra.Command, args []string) { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
name = args[0] |
|
|
|
name = args[0] |
|
|
|
} |
|
|
|
} |
|
|
|
wd = getProjectPlaceDir(name, wd) |
|
|
|
projectName, workingDir := processProjectParams(name, wd) |
|
|
|
p := &Project{Name: filepath.Base(name), Path: name} |
|
|
|
p := &Project{Name: projectName, Path: projectName} |
|
|
|
done := make(chan error, 1) |
|
|
|
done := make(chan error, 1) |
|
|
|
go func() { |
|
|
|
go func() { |
|
|
|
if !nomod { |
|
|
|
if !nomod { |
|
|
|
done <- p.New(ctx, wd, repoURL, branch) |
|
|
|
done <- p.New(ctx, workingDir, repoURL, branch) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
projectRoot := getgomodProjectRoot(wd) |
|
|
|
projectRoot := getgomodProjectRoot(workingDir) |
|
|
|
if gomodIsNotExistIn(projectRoot) { |
|
|
|
if gomodIsNotExistIn(projectRoot) { |
|
|
|
done <- fmt.Errorf("🚫 go.mod don't exists in %s", projectRoot) |
|
|
|
done <- fmt.Errorf("🚫 go.mod don't exists in %s", projectRoot) |
|
|
|
return |
|
|
|
return |
|
|
@ -84,7 +84,7 @@ func run(cmd *cobra.Command, args []string) { |
|
|
|
if e != nil { |
|
|
|
if e != nil { |
|
|
|
panic(e) |
|
|
|
panic(e) |
|
|
|
} |
|
|
|
} |
|
|
|
done <- p.Add(ctx, wd, repoURL, branch, mod) |
|
|
|
done <- p.Add(ctx, workingDir, repoURL, branch, mod) |
|
|
|
}() |
|
|
|
}() |
|
|
|
select { |
|
|
|
select { |
|
|
|
case <-ctx.Done(): |
|
|
|
case <-ctx.Done(): |
|
|
@ -100,29 +100,29 @@ func run(cmd *cobra.Command, args []string) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getProjectPlaceDir(projectName string, fallbackPlaceDir string) string { |
|
|
|
func processProjectParams(projectName string, workingDir string) (projectNameResult, workingDirResult string) { |
|
|
|
projectFullPath := projectName |
|
|
|
_projectDir := projectName |
|
|
|
|
|
|
|
_workingDir := workingDir |
|
|
|
wd := filepath.Dir(projectName) |
|
|
|
// Process ProjectName with system variable
|
|
|
|
// check for home dir
|
|
|
|
if strings.HasPrefix(projectName, "~") { |
|
|
|
if strings.HasPrefix(wd, "~") { |
|
|
|
|
|
|
|
homeDir, err := os.UserHomeDir() |
|
|
|
homeDir, err := os.UserHomeDir() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
// cannot get user home return fallback place dir
|
|
|
|
// cannot get user home return fallback place dir
|
|
|
|
return fallbackPlaceDir |
|
|
|
return _projectDir, _workingDir |
|
|
|
} |
|
|
|
} |
|
|
|
projectFullPath = filepath.Join(homeDir, projectName[2:]) |
|
|
|
_projectDir = filepath.Join(homeDir, projectName[2:]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// check path is relative
|
|
|
|
// check path is relative
|
|
|
|
if !filepath.IsAbs(projectFullPath) { |
|
|
|
if !filepath.IsAbs(projectName) { |
|
|
|
absPath, err := filepath.Abs(projectFullPath) |
|
|
|
absPath, err := filepath.Abs(projectName) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return fallbackPlaceDir |
|
|
|
return _projectDir, _workingDir |
|
|
|
} |
|
|
|
} |
|
|
|
projectFullPath = absPath |
|
|
|
_projectDir = absPath |
|
|
|
} |
|
|
|
} |
|
|
|
// create project logic will check stat,so not check path stat here
|
|
|
|
|
|
|
|
return filepath.Dir(projectFullPath) |
|
|
|
return filepath.Base(_projectDir), filepath.Dir(_projectDir) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getgomodProjectRoot(dir string) string { |
|
|
|
func getgomodProjectRoot(dir string) string { |
|
|
|