-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
action.go
61 lines (56 loc) · 1.22 KB
/
action.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
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"os"
"github.com/urfave/cli"
)
func action(ctx *cli.Context) error {
config, errors := makeConfig(ctx)
if errors != nil {
hasErr := false
for _, err := range errors {
if err.Error() != "" {
fmt.Fprintf(os.Stderr, err.Error()+"\n")
hasErr = true
}
}
if hasErr {
fmt.Fprintf(os.Stderr, "\n")
}
cli.ShowAppHelp(ctx)
} else {
dependency, errors := gatherDependency(config)
output(config, dependency, errors)
}
return nil
}
func output(config *Config, dependency *Dependency, errors []error) {
for _, err := range errors {
fmt.Fprintf(os.Stderr, err.Error()+"\n")
}
switch config.Format {
case "dot":
outputDot(config.Output, dependency)
case "csv":
outputCsv(config.Output, dependency)
case "tsv":
outputTsv(config.Output, dependency)
case "json":
outputJSON(config.Output, dependency)
default:
outputDefault(config.Output, dependency)
}
}
func gatherDependency(config *Config) (*Dependency, []error) {
var errors []error
dependency := newDependency()
for _, path := range config.Paths {
deps, err := extract(path, config)
if err != nil {
errors = append(errors, err...)
} else {
dependency.concat(deps)
}
}
return dependency, errors
}