/
licenser.go
95 lines (76 loc) · 2.53 KB
/
licenser.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package licenser
import (
"fmt"
"time"
"github.com/athopen/licenser/internal/repository/npm"
"github.com/athopen/licenser/internal/repository"
"github.com/athopen/licenser/internal/repository/composer"
"github.com/spf13/afero"
"github.com/symfony-cli/console"
)
var (
// version is overridden at linking time
version = "dev"
// overridden at linking time
buildDate string
)
var (
fs = afero.NewOsFs()
)
var (
managerArg = &console.Arg{Name: "manager", Description: "The package manager (composer or npm)"}
)
var (
fileFlag = &console.StringFlag{Name: "file", Usage: "Config file"}
dirFlag = &console.StringFlag{Name: "dir", Usage: "Working directory"}
noDevFlag = &console.BoolFlag{Name: "no-dev", Usage: "Exclude require-dev packages"}
)
var (
factories = map[string]repository.Factory{
"composer": composer.Factory,
"npm": npm.Factory,
}
)
func resolveFactory(manager string) (repository.Factory, error) {
factory, exists := factories[manager]
if !exists {
return nil, fmt.Errorf("package manager \"%s\" is not supported", manager)
}
return factory, nil
}
var (
helpTemplate = `<info>
_____ _______ _______ __ _ _______ _______ ______
| | | |______ | \ | |______ |______ |_____/
|_____ __|__ |_____ |______ | \_| ______| |______ | \_
</>
<info>{{.Name}}</>{{if .Version}} version <comment>{{.Version}}</>{{end}}{{if .Copyright}} {{.Copyright}}{{end}}
{{.Usage}}
<comment>Usage</>:
{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} <command> [command options]{{end}} [arguments...]{{if .Description}}
{{.Description}}{{end}}{{if .VisibleFlags}}
<comment>Global options:</>
{{range $index, $option := .VisibleFlags}}{{if $index}}
{{end}}{{$option}}{{end}}{{end}}{{if .VisibleCommands}}
<comment>Available commands:</>{{range .VisibleCategories}}{{if .Name}}
<comment>{{.Name}}</>{{"\t"}}{{end}}{{range .VisibleCommands}}
<info>{{join .Names ", "}}</>{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}
`
)
func Application() *console.Application {
return &console.Application{
Name: "licenser",
Copyright: fmt.Sprintf("(c) %d <info>Andreas Penz <andreas.penz.1989@gmail.com></>", time.Now().Year()),
Usage: "Licenser is a tool designed to check and report on the licenses used by a package and its dependencies.",
Action: func(ctx *console.Context) error {
console.HelpPrinter(ctx.App.Writer, helpTemplate, ctx.App)
return nil
},
Commands: []*console.Command{
infoCommand(),
checkCommand(),
},
Version: version,
BuildDate: buildDate,
}
}