|
5 | 5 | "errors" |
6 | 6 | "io" |
7 | 7 | "log/slog" |
| 8 | + "os" |
8 | 9 | "testing" |
9 | 10 |
|
10 | 11 | scalibr "github.com/google/osv-scalibr/version" |
|
23 | 24 | type CommandBuilder = func(stdout, stderr io.Writer) *cli.Command |
24 | 25 |
|
25 | 26 | func Run(args []string, stdout, stderr io.Writer, commands []CommandBuilder) int { |
| 27 | + // urfave/cli uses a global for its help flag which makes it possible for a nil |
| 28 | + // pointer dereference if running in a parallel setting, which our test suite |
| 29 | + // does, so this is used to hide the help flag so the global won't be used |
| 30 | + // unless a particular env variable is set |
| 31 | + // |
| 32 | + // see https://github.com/urfave/cli/issues/2176 |
| 33 | + shouldHideHelp := testing.Testing() && os.Getenv("TEST_SHOW_HELP") != "true" |
| 34 | + |
26 | 35 | // --- Setup Logger --- |
27 | 36 | logHandler := cmdlogger.New(stdout, stderr) |
28 | 37 |
|
@@ -50,14 +59,18 @@ func Run(args []string, stdout, stderr io.Writer, commands []CommandBuilder) int |
50 | 59 |
|
51 | 60 | cmds := make([]*cli.Command, 0, len(commands)) |
52 | 61 | for _, cmd := range commands { |
53 | | - cmds = append(cmds, cmd(stdout, stderr)) |
| 62 | + c := cmd(stdout, stderr) |
| 63 | + c.HideHelp = shouldHideHelp |
| 64 | + |
| 65 | + cmds = append(cmds, c) |
54 | 66 | } |
55 | 67 |
|
56 | 68 | app := &cli.Command{ |
57 | 69 | Name: "osv-scanner", |
58 | 70 | Version: version.OSVVersion, |
59 | 71 | Usage: "scans various mediums for dependencies and checks them against the OSV database", |
60 | 72 | Suggest: true, |
| 73 | + HideHelp: shouldHideHelp, |
61 | 74 | Writer: stdout, |
62 | 75 | ErrWriter: stderr, |
63 | 76 | DefaultCommand: "scan", |
|
0 commit comments