fix(cli): report mistyped subcommand before options - #504
Conversation
|
/ai-review |
|
The logic looks correct and the tests cover the key cases. One edge case worth flagging:
When the user types Minor redundancy in the condition chain The if (firstArg == null) {
group.help()
} else if (firstArg !== '--' && firstArg.startsWith('-')) {
group.error(`unknown option '${firstArg}'`)
} else {
const cmd = firstArg === '--' ? this.args[1] : firstArg
if (cmd != null) {
group.error(`unknown command: ${cmd}`)
} else {
group.help() // bare '--' with nothing after
}
}Not a bug, just clarity. Test boilerplate Each test creates and tears down its own temp dir + config file with identical content. This works but repeats ~10 lines per test. A Nothing else is wrong. |
|
should i fix this or not since its not a functionality issue @margaretjgu |
|
Please address the condition simplification. Even though it doesn't affect functionality, cleaner and more readable code should be enforced for maintainability :) we want to avoid additional tech debt |
Summary
Why
Command groups validated unknown options before their default action could identify an invalid subcommand. As a result,
elastic stack es serch --index my-indexreported--indexas unknown instead of identifying theserchtypo.Testing
npm testnpm run test:lintnpm run test:spdxnpm run test:noticeCloses #501