From 7939ab12a953ad0e087ca64ab87fd11d75b01710 Mon Sep 17 00:00:00 2001 From: Holly Gong <39108850+hogo6002@users.noreply.github.com> Date: Fri, 24 Jan 2025 15:34:41 +1100 Subject: [PATCH] fix(cmd): udpate warning message (#1530) correct warning message --- cmd/osv-scanner/__snapshots__/fix_test.snap | 12 ++++++------ cmd/osv-scanner/__snapshots__/main_test.snap | 2 +- cmd/osv-scanner/__snapshots__/update_test.snap | 2 +- cmd/osv-scanner/main.go | 10 ++++++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cmd/osv-scanner/__snapshots__/fix_test.snap b/cmd/osv-scanner/__snapshots__/fix_test.snap index c8b6803134..62ead08158 100755 --- a/cmd/osv-scanner/__snapshots__/fix_test.snap +++ b/cmd/osv-scanner/__snapshots__/fix_test.snap @@ -13,7 +13,7 @@ Rewriting /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. --- @@ -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 /package-lock.json... Rewriting /package-lock.json... @@ -3877,7 +3877,7 @@ Rewriting /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 /pom.xml... Rewriting /pom.xml... @@ -4030,7 +4030,7 @@ Rewriting /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 /package.json... Rewriting /package.json... @@ -4070,7 +4070,7 @@ Rewriting /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. --- @@ -4134,7 +4134,7 @@ Rewriting /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. --- diff --git a/cmd/osv-scanner/__snapshots__/main_test.snap b/cmd/osv-scanner/__snapshots__/main_test.snap index b9fdcc4925..98f14e1d86 100755 --- a/cmd/osv-scanner/__snapshots__/main_test.snap +++ b/cmd/osv-scanner/__snapshots__/main_test.snap @@ -1344,7 +1344,7 @@ Scanned /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. --- diff --git a/cmd/osv-scanner/__snapshots__/update_test.snap b/cmd/osv-scanner/__snapshots__/update_test.snap index 800d3cc0a1..10e8cd893a 100755 --- a/cmd/osv-scanner/__snapshots__/update_test.snap +++ b/cmd/osv-scanner/__snapshots__/update_test.snap @@ -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. --- diff --git a/cmd/osv-scanner/main.go b/cmd/osv-scanner/main.go index 4cde9b9e82..1b48da6cc5 100644 --- a/cmd/osv-scanner/main.go +++ b/cmd/osv-scanner/main.go @@ -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) } } @@ -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 { @@ -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