Skip to content

Commit c27bfad

Browse files
committed
Add a licenses subcommand that prints the licenses of all dependencies.
1 parent f83699f commit c27bfad

File tree

16 files changed

+279
-1
lines changed

16 files changed

+279
-1
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
uses: actions/setup-go@v2
2020
with:
2121
go-version: 1.14.7
22+
- name: Install Pkger
23+
run: go get github.com/markbates/pkger/cmd/pkger
2224
- name: Build
2325
uses: goreleaser/goreleaser-action@v2
2426
with:

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
uses: actions/setup-go@v2
1919
with:
2020
go-version: 1.14.7
21+
- name: Install Pkger
22+
run: go get github.com/markbates/pkger/cmd/pkger
2123
- name: Release
2224
uses: goreleaser/goreleaser-action@v2
2325
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/codeql-action-sync
22
/dist/
3+
/pkged.go

.goreleaser.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
project_name: codeql-action-sync
22

3+
before:
4+
hooks:
5+
- pkger
6+
37
builds:
48
- goos: [linux, darwin, windows]
59
goarch: [386, amd64, arm64]

.licenses/go/github.com/gobuffalo/here.dep.yml

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.licenses/go/github.com/markbates/pkger.dep.yml

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.licenses/go/github.com/markbates/pkger/here.dep.yml

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.licenses/go/github.com/markbates/pkger/internal/maps.dep.yml

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.licenses/go/github.com/markbates/pkger/pkging.dep.yml

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.licenses/go/github.com/markbates/pkger/pkging/stdos.dep.yml

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.licenses/go/github.com/spf13/pflag.dep.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/licenses.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package cmd
2+
3+
import (
4+
"github.com/github/codeql-action-sync/internal/licenses"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
var licensesCmd = &cobra.Command{
9+
Use: "licenses",
10+
Short: "Display the licenses of all the dependencies of this tool.",
11+
RunE: func(cmd *cobra.Command, args []string) error {
12+
return licenses.PrintLicenses()
13+
},
14+
}

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func Execute(ctx context.Context) error {
5151
}
5252

5353
rootCmd.AddCommand(versionCmd)
54+
rootCmd.AddCommand(licensesCmd)
5455

5556
rootCmd.AddCommand(pullCmd)
5657
pullFlags.Init(pullCmd)

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ require (
66
github.com/go-git/go-git/v5 v5.1.0
77
github.com/google/go-github/v32 v32.1.0
88
github.com/gorilla/mux v1.8.0
9+
github.com/markbates/pkger v0.17.0
910
github.com/mitchellh/ioprogress v0.0.0-20180201004757-6a23b12fa88e
1011
github.com/pkg/errors v0.8.1
1112
github.com/spf13/cobra v1.0.0
13+
github.com/spf13/pflag v1.0.5 // indirect
1214
github.com/stretchr/testify v1.6.1
15+
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
16+
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
1317
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
18+
golang.org/x/sys v0.0.0-20200824131525-c12d262b63d8 // indirect
1419
)

go.sum

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/licenses/licenses.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package licenses
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"os"
7+
8+
"github.com/markbates/pkger"
9+
"github.com/pkg/errors"
10+
)
11+
12+
const errorMessage = "Error reading licenses."
13+
14+
func PrintLicenses() error {
15+
fmt.Println("This tool could not have been built without all the wonderful developer communities who maintain these dependencies.")
16+
err := pkger.Walk("/.licenses", func(path string, info os.FileInfo, err error) error {
17+
if err != nil {
18+
return errors.Wrap(err, errorMessage)
19+
}
20+
if info.IsDir() {
21+
return nil
22+
}
23+
24+
reader, err := pkger.Open(path)
25+
if err != nil {
26+
return errors.Wrap(err, errorMessage)
27+
}
28+
defer reader.Close()
29+
content, err := ioutil.ReadAll(reader)
30+
if err != nil {
31+
return errors.Wrap(err, errorMessage)
32+
}
33+
fmt.Println(string(content))
34+
35+
return nil
36+
})
37+
if err != nil {
38+
return errors.Wrap(err, errorMessage)
39+
}
40+
return nil
41+
}

0 commit comments

Comments
 (0)