Skip to content

Commit e69cf6e

Browse files
lavrdBobgy
andauthored
Added flags to avoid duplicate output on errors and print all forbidden licenses before exit (#60)
Co-authored-by: Yuan (Bob) Gong <4957653+Bobgy@users.noreply.github.com>
1 parent 94bf8c3 commit e69cf6e

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ Forbidden license type WTFPL for library github.com/logrusorgru/auroraexit statu
120120
This command analyzes a package's dependencies and determines if any are
121121
considered forbidden by the license classifer. See
122122
[github.com/google/licenseclassifier](https://github.com/google/licenseclassifier/blob/842c0d70d7027215932deb13801890992c9ba364/license_type.go#L323)
123-
124123
for licenses considered forbidden.
125124

126125
## Usages

check.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,25 @@ func checkMain(_ *cobra.Command, args []string) error {
4848
if err != nil {
4949
return err
5050
}
51+
52+
// indicate that a forbidden license was found
53+
found := false
54+
5155
for _, lib := range libs {
5256
licenseName, licenseType, err := classifier.Identify(lib.LicensePath)
5357
if err != nil {
5458
return err
5559
}
60+
5661
if licenseType == licenses.Forbidden {
5762
fmt.Fprintf(os.Stderr, "Forbidden license type %s for library %v\n", licenseName, lib)
58-
os.Exit(1)
63+
found = true
5964
}
6065
}
66+
67+
if found {
68+
os.Exit(1)
69+
}
70+
6171
return nil
6272
}

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ func init() {
7070
func main() {
7171
flag.Parse()
7272
rootCmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
73+
rootCmd.SilenceErrors = true // to avoid duplicate error output
74+
rootCmd.SilenceUsage = true // to avoid usage/help output on error
7375

7476
if err := rootCmd.Execute(); err != nil {
7577
glog.Exit(err)

0 commit comments

Comments
 (0)