-
-
Notifications
You must be signed in to change notification settings - Fork 89
feat: append --help hint to unknown option errors #712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,9 +51,9 @@ export function parseArgs(argv: string[]): { | |
| continue; | ||
| } | ||
| if (arg.startsWith("-")) { | ||
| throw new Error(`Unknown option: ${arg}`); | ||
| throw new Error(`Unknown option: ${arg} Run \`cve-lite --help\` to see supported options.`); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth noting: the hint is applied to 3 of the 6 throw sites in |
||
| } | ||
| throw new Error(`Unexpected argument: ${arg}`); | ||
| throw new Error(`Unexpected argument: ${arg} Run \`cve-lite --help\` to see supported options.`); | ||
| } | ||
|
|
||
| return { command: "advisories-sync", options }; | ||
|
|
@@ -67,9 +67,9 @@ export function parseArgs(argv: string[]): { | |
| continue; | ||
| } | ||
| if (arg.startsWith("-")) { | ||
| throw new Error(`Unknown option: ${arg}`); | ||
| throw new Error(`Unknown option: ${arg} Run \`cve-lite --help\` to see supported options.`); | ||
| } | ||
| throw new Error(`Unexpected argument: ${arg}`); | ||
| throw new Error(`Unexpected argument: ${arg} Run \`cve-lite --help\` to see supported options.`); | ||
| } | ||
| return { command: "install-skill", options }; | ||
| } | ||
|
|
@@ -267,13 +267,13 @@ export function parseArgs(argv: string[]): { | |
| continue; | ||
| } | ||
| if (arg.startsWith("-")) { | ||
| throw new Error(`Unknown option: ${arg}`); | ||
| throw new Error(`Unknown option: ${arg} Run \`cve-lite --help\` to see supported options.`); | ||
| } | ||
| if (!projectArg) { | ||
| projectArg = arg; | ||
| continue; | ||
| } | ||
| throw new Error(`Unexpected argument: ${arg}`); | ||
| throw new Error(`Unexpected argument: ${arg} Run \`cve-lite --help\` to see supported options.`); | ||
| } | ||
|
|
||
| if (options.cdx && options.report) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,9 @@ try { | |
| } catch (error) { | ||
| const message = error instanceof Error ? error.message : String(error); | ||
| console.error(chalk.red(`Error: ${message}`)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This guard exists because embedding the hint in |
||
| console.error(chalk.gray("Run `cve-lite --help` to see supported options.")); | ||
| if (!message.includes("--help")) { | ||
| console.error(chalk.gray("Run `cve-lite --help` to see supported options.")); | ||
| } | ||
| process.exit(1); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
--helphint belongs at the render layer inindex.ts, not embedded inError.message.Error.messageis a programmatic value - callers that catch this error get a string that mixes the machine-readable fact (Unknown option: --foo) with display copy. Thecatchblock inindex.tsis already the right place to append the hint, and it already does so. Keep the throw messages clean.