Skip to content

Commit

Permalink
fix(cmd): udpate warning message (#1530)
Browse files Browse the repository at this point in the history
correct warning message
  • Loading branch information
hogo6002 authored Jan 24, 2025
1 parent 0e88d4f commit 7939ab1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
12 changes: 6 additions & 6 deletions cmd/osv-scanner/__snapshots__/fix_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Rewriting <tempdir>/package-lock.json...
---

[TestRun_Fix/fix_non-interactive_in-place_package-lock.json - 2]
Warning: `fix` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `fix` is assumed to be a subcommand here. If you intended for `fix` to be an argument to `fix`, you must specify `fix fix` in your command line.
Warning: `fix` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `fix` is assumed to be a subcommand here. If you intended for `fix` to be an argument to `scan`, you must specify `scan fix` in your command line.

---

Expand Down Expand Up @@ -1867,7 +1867,7 @@ Warning: `fix` exists as both a subcommand of OSV-Scanner and as a file on the f
---

[TestRun_Fix/fix_non-interactive_json_in-place_package-lock.json - 2]
Warning: `fix` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `fix` is assumed to be a subcommand here. If you intended for `fix` to be an argument to `fix`, you must specify `fix fix` in your command line.
Warning: `fix` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `fix` is assumed to be a subcommand here. If you intended for `fix` to be an argument to `scan`, you must specify `scan fix` in your command line.
Scanning <tempdir>/package-lock.json...
Rewriting <tempdir>/package-lock.json...

Expand Down Expand Up @@ -3877,7 +3877,7 @@ Rewriting <tempdir>/package-lock.json...
---

[TestRun_Fix/fix_non-interactive_json_override_pom.xml - 2]
Warning: `fix` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `fix` is assumed to be a subcommand here. If you intended for `fix` to be an argument to `fix`, you must specify `fix fix` in your command line.
Warning: `fix` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `fix` is assumed to be a subcommand here. If you intended for `fix` to be an argument to `scan`, you must specify `scan fix` in your command line.
Resolving <tempdir>/pom.xml...
Rewriting <tempdir>/pom.xml...

Expand Down Expand Up @@ -4030,7 +4030,7 @@ Rewriting <tempdir>/pom.xml...
---

[TestRun_Fix/fix_non-interactive_json_relax_package.json - 2]
Warning: `fix` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `fix` is assumed to be a subcommand here. If you intended for `fix` to be an argument to `fix`, you must specify `fix fix` in your command line.
Warning: `fix` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `fix` is assumed to be a subcommand here. If you intended for `fix` to be an argument to `scan`, you must specify `scan fix` in your command line.
Resolving <tempdir>/package.json...
Rewriting <tempdir>/package.json...

Expand Down Expand Up @@ -4070,7 +4070,7 @@ Rewriting <tempdir>/pom.xml...
---

[TestRun_Fix/fix_non-interactive_override_pom.xml - 2]
Warning: `fix` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `fix` is assumed to be a subcommand here. If you intended for `fix` to be an argument to `fix`, you must specify `fix fix` in your command line.
Warning: `fix` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `fix` is assumed to be a subcommand here. If you intended for `fix` to be an argument to `scan`, you must specify `scan fix` in your command line.

---

Expand Down Expand Up @@ -4134,7 +4134,7 @@ Rewriting <tempdir>/package.json...
---

[TestRun_Fix/fix_non-interactive_relax_package.json - 2]
Warning: `fix` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `fix` is assumed to be a subcommand here. If you intended for `fix` to be an argument to `fix`, you must specify `fix fix` in your command line.
Warning: `fix` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `fix` is assumed to be a subcommand here. If you intended for `fix` to be an argument to `scan`, you must specify `scan fix` in your command line.

---

Expand Down
2 changes: 1 addition & 1 deletion cmd/osv-scanner/__snapshots__/main_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ Scanned <rootdir>/fixtures/locks-insecure/osv-scanner-flutter-deps.json file as
---

[TestRun_InsertDefaultCommand - 6]
Warning: `scan` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `scan` is assumed to be a subcommand here. If you intended for `scan` to be an argument to `scan`, you must specify `scan scan` in your command line.
Warning: `scan` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `scan` is assumed to be a subcommand here. If you intended for `scan` to be an argument to `default`, you must specify `default scan` in your command line.

---

Expand Down
2 changes: 1 addition & 1 deletion cmd/osv-scanner/__snapshots__/update_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
---

[TestRun_Update/update_pom.xml_with_in-place_changes - 2]
Warning: `update` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `update` is assumed to be a subcommand here. If you intended for `update` to be an argument to `update`, you must specify `update update` in your command line.
Warning: `update` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `update` is assumed to be a subcommand here. If you intended for `update` to be an argument to `scan`, you must specify `scan update` in your command line.

---

Expand Down
10 changes: 6 additions & 4 deletions cmd/osv-scanner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ func getAllCommands(commands []*cli.Command) []string {
// warnIfCommandAmbiguous warns the user if the command they are trying to run
// exists as both a subcommand and as a file on the filesystem.
// If this is the case, the command is assumed to be a subcommand.
func warnIfCommandAmbiguous(command string, stdout, stderr io.Writer) {
func warnIfCommandAmbiguous(command, defaultCommand string, stdout, stderr io.Writer) {
if _, err := os.Stat(command); err == nil {
r := reporter.NewJSONReporter(stdout, stderr, reporter.InfoLevel)
r.Warnf("Warning: `%[1]s` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. `%[1]s` is assumed to be a subcommand here. If you intended for `%[1]s` to be an argument to `%[1]s`, you must specify `%[1]s %[1]s` in your command line.\n", command)
r.Warnf("Warning: `%[1]s` exists as both a subcommand of OSV-Scanner and as a file on the filesystem. "+
"`%[1]s` is assumed to be a subcommand here. If you intended for `%[1]s` to be an argument to `%[2]s`, "+
"you must specify `%[2]s %[1]s` in your command line.\n", command, defaultCommand)
}
}

Expand All @@ -176,7 +178,7 @@ func insertDefaultCommand(args []string, commands []*cli.Command, defaultCommand
return argsTmp
}

warnIfCommandAmbiguous(command, stdout, stderr)
warnIfCommandAmbiguous(command, defaultCommand, stdout, stderr)

// If only the default command is provided without its subcommand, append the subcommand.
if command == defaultCommand {
Expand All @@ -197,7 +199,7 @@ func insertDefaultCommand(args []string, commands []*cli.Command, defaultCommand
}

// Print a warning message if subcommand exist on the filesystem.
warnIfCommandAmbiguous(subcommand, stdout, stderr)
warnIfCommandAmbiguous(subcommand, scan.DefaultSubcommand, stdout, stderr)
}

return args
Expand Down

0 comments on commit 7939ab1

Please sign in to comment.