forked from dave/courtney
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.go
53 lines (46 loc) · 1023 Bytes
/
shared.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
47
48
49
50
51
52
53
package shared
import (
"strings"
"github.com/dave/patsy"
"github.com/dave/patsy/vos"
)
// Setup holds globals, environment and command line flags for the courtney
// command
type Setup struct {
Env vos.Env
Paths *patsy.Cache
Enforce bool
Verbose bool
Short bool
Timeout string
Load string
Output string
TestArgs []string
Packages []PackageSpec
}
// PackageSpec identifies a package by dir and path
type PackageSpec struct {
Dir string
Path string
}
// Parse parses a slice of strings into the Packages slice
func (s *Setup) Parse(args []string) error {
if len(args) == 0 {
args = []string{"./..."}
}
packages := map[string]string{}
for _, ppath := range args {
ppath = strings.TrimSuffix(ppath, "/")
paths, err := s.Paths.Dirs(ppath)
if err != nil {
return err
}
for importPath, dir := range paths {
packages[importPath] = dir
}
}
for ppath, dir := range packages {
s.Packages = append(s.Packages, PackageSpec{Path: ppath, Dir: dir})
}
return nil
}