cht-core icon indicating copy to clipboard operation
cht-core copied to clipboard

fix(#10951): centralize CLI command validation

Open CodeWith-sakib opened this issue 7 months ago • 3 comments

fix(#10951): centralize CLI command validation and remove duplicated dispatch logic

Description

The command dispatch logic in scripts/build/cli.js and scripts/build/ddoc-compile.js was duplicated and relied on direct access to process.argv[2] without validation.

This caused:

  • Unclear failures for missing commands
  • Uncaught exceptions for invalid commands
  • Lack of consistent error handling across scripts

Changes

  • Extracted command lookup and validation into a shared helper (scripts/build/get-command.js)

  • Updated both CLI entrypoints to use the shared helper

  • Added consistent error handling:

    • Clear error messages for missing/unknown commands
    • Controlled exit with status code 1
  • Removed duplicated command parsing logic

Behavior

  • No change for valid commands
  • Improved handling for invalid or missing commands (now fails cleanly with helpful output)

Closes #10951

Code review checklist

  • [x] Readable: Concise, well named, follows the style guide
  • [ ] Documented: Configuration and user documentation on cht-docs
  • [ ] Tested: Unit and/or e2e where appropriate
  • [ ] Internationalised: All user facing text
  • [x] Backwards compatible: No breaking changes to existing command behavior
  • [x] AI disclosure: This PR was created with assistance from AI tools for drafting and refinement, with manual validation and testing performed before submission.

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

CodeWith-sakib avatar Apr 30 '26 06:04 CodeWith-sakib

@CodeWith-sakib can you please address the sonar linting issues?

dianabarsan avatar Apr 30 '26 10:04 dianabarsan

Hey @dianabarsan , I’ve addressed the Sonar linting issue by updating the sorting logic to use localeCompare for consistent behavior.

Please let me know if anything else needs attention.

CodeWith-sakib avatar Apr 30 '26 13:04 CodeWith-sakib

This PR is now marked "stale" after 30 days without activity. It will be closed automatically in 10 days unless you add a comment, push new changes or remove the "stale" label.

github-actions[bot] avatar Jun 04 '26 00:06 github-actions[bot]