-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
46 lines (35 loc) · 967 Bytes
/
run.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/urfave/cli"
git "gopkg.in/src-d/go-git.v4"
)
func run(c *cli.Context) error {
var (
err error
goPath string
goSourcePath string
gitRepositoryPath = c.String("repo-path")
gitSubmodules git.Submodules
sharedModules []SharedModule
)
if len(gitRepositoryPath) == 0 {
return fmt.Errorf("repo-path must be supplied")
}
goPath = os.Getenv("GOPATH")
if len(goPath) == 0 {
return fmt.Errorf("unable to find GOPATH")
}
goSourcePath = fmt.Sprintf("%s/", filepath.Join(goPath, "src"))
if gitSubmodules, err = getSubmodulesFromRepositoryPath(gitRepositoryPath); err != nil {
return err
}
if sharedModules, err = convertGitModulesToSharedModule(gitSubmodules); err != nil {
return err
}
projectPath := strings.Replace(gitRepositoryPath, goSourcePath, "", 1)
return writeGoModFile(os.Stdout, projectPath, sharedModules)
}