Skip to content

Improve CLI Help and Argument Handling in update_firmware.py#33

Open
ChasonDeshotel wants to merge 1 commit intobeacon3d:masterfrom
ChasonDeshotel:improve-cli-help
Open

Improve CLI Help and Argument Handling in update_firmware.py#33
ChasonDeshotel wants to merge 1 commit intobeacon3d:masterfrom
ChasonDeshotel:improve-cli-help

Conversation

@ChasonDeshotel
Copy link

✨ Improvements to update_firmware.py

Enhancements:

  • Better CLI UX: Added descriptive help text, usage examples, and behavioral notes.
  • Graceful Fallback: Now prints full help message when no subcommand is given, instead of a terse argparse error.
  • Command Dispatch Refactor: Removed globals() dispatch in favor of an explicit dict-based dispatch table.
  • Consistent Output and Shared Error Handling: Standardized output messages across check and update tasks.

Example behavior:

$ python3 update_firmware.py
usage: update_firmware.py [-h] {check,update} ...

Beacon firmware updater

Examples:
  update_firmware.py check /dev/serial/by-id/...
  update_firmware.py update /dev/serial/by-id/...

Notes:
  - 'check' produces no output if firmware is up-to-date
  - 'update' uses 'sudo' unless --no-sudo is specified
  - Use --force to flash even if the firmware appears current

positional arguments:
  {check,update}  Available commands
    check         Check if firmware is up to date
    update        Update firmware

options:
  -h, --help      Show this help message and exit

Why?

Because I had to read code to see if returning nothing meant success

This change is low risk and improves clarity and maintainability

Add descriptive help text, usage examples, and behavioral notes
Prints full help message when no subcommand is given
Remove globals() dispatch in favor of an explicit dict-based dispatch table
Standardize output messages across check and update tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant