-
Notifications
You must be signed in to change notification settings - Fork 1
/
list.go
49 lines (40 loc) · 1.04 KB
/
list.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
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/nextlinux/go-bouncer/bouncer"
"github.com/nextlinux/go-bouncer/bouncer/presenter"
)
var gitRemotes []string
// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list",
Short: "List all discovered licenses for a project (including dependencies)",
Run: func(cmd *cobra.Command, args []string) {
err := doListCmd(cmd, args)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
},
}
func init() {
listCmd.Flags().StringArrayVar(&gitRemotes, "git-remote", []string{"origin", "upstream"}, "Remote Git repositories to try")
rootCmd.AddCommand(listCmd)
}
func doListCmd(_ *cobra.Command, args []string) error {
var paths []string
if len(args) > 0 {
paths = args
} else {
paths = []string{"."}
}
licenseFinder := bouncer.NewLicenseFinder(paths, gitRemotes, 0.9)
resultStream, err := licenseFinder.Find()
if err != nil {
return err
}
pres := presenter.GetPresenter(appConfig.PresenterOpt, resultStream)
return pres.Present(os.Stdout)
}