Skip to content

feat(cli): add --version, colorize errors, migrate sm-settings to Typer - #59

Closed
antosubash wants to merge 3 commits into
mainfrom
claude/improve-cli-wn0WW
Closed

antosubash wants to merge 3 commits into
mainfrom
claude/improve-cli-wn0WW

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Summary

Polishes the three console scripts (sm, sm-users, sm-settings) so they behave consistently and give readable feedback:

  • --version / -V on all three. None of them exposed a version flag before; they all resolve it from importlib.metadata (falls back to "unknown" when the package isn't installed, so it's safe in dev checkouts).
  • Colored output in sm and sm-users. ERROR:/WARNING: prefixes now render red/yellow via click.secho / typer.secho, and success messages render green. No behavioral changes — exit codes and message substrings are preserved.
  • sm-settings swapped its hand-rolled argv parser for a Typer app. The old main() was ~30 lines of manual sys.argv[1:] juggling with a bare print() for help and "Unknown command:" for anything else. It now gets real --help, real subcommand dispatch, and shell-completion scaffolding for free, matching the sm-users style. import_from_env_impl is unchanged, so the existing tests (which import it directly) continue to pass. Added typer>=0.12 to modules/settings/pyproject.toml dependencies.
  • -h everywhere. help_option_names is set on all three so -h works as an alias for --help.
  • Trimmed the sm CLI docstrings to keep the file under the repo's 300-line cap after the additions.

Test plan

  • uv run pytest --no-header -q — 977 passed
  • uv run ruff check + uv run ruff format --check on the three CLI files — clean
  • uv run python scripts/check_file_size.py — OK: no files exceed 300 lines
  • uv run sm --version, uv run sm-users --version, uv run sm-settings --version — all print <name> 0.0.1
  • uv run sm --help, sm-users --help, sm-settings --help — render; Typer shows rich-formatted help

https://claude.ai/code/session_01UZwR7S8JzFtWSSArVbzF7A


Generated by Claude Code

claude added 3 commits April 24, 2026 14:23
- sm / sm-users / sm-settings all expose -V/--version and -h/--help
- sm / sm-users colorize success (green), warnings (yellow), errors (red)
- sm-settings dropped its hand-rolled argv parser in favour of a Typer app,
  matching sm-users and giving it a real --help, subcommand dispatch, and
  shell completion hooks out of the box
…rror

- new `sm list-modules` prints a tabular view of every module discovered
  via [project.entry-points.simple_module] (name, version, package)
- `sm new` now announces each install step (`==> uv sync`, `==> npm
  install`, `==> uv run alembic upgrade head`) in cyan so the long silent
  stretch is replaced with visible progress
- `gen-pages` and `sync-js-deps` now attach a `hint:` line when the
  client_app directory isn't found, pointing at the escape hatch flag
- `sm --help` ends with a short `Examples:` epilog
- extracted color helpers + the modules-listing printer into
  simple_module_hosting/_cli_utils.py so cli.py stays under the 300-line
  cap (error now also accepts an optional hint=)
- added tests for --version, list-modules, and the hinted client_app error
…tings

Previously each module exposed its own console script (`sm-users`,
`sm-settings`) — three entry points on PATH for what is really one tool.
Now every command lives under `sm`, with each module contributing a
subgroup via the new `simple_module_cli` entry-point group:

    sm users create-admin --email ... --password ...
    sm settings import-from-env

Implementation:

- new `attach_plugin_commands(main)` helper in _cli_utils.py walks
  `importlib.metadata.entry_points(group="simple_module_cli")` and
  attaches each loaded click.Command / click.Group to the top-level `sm`
  group. Broken plugins are logged and skipped so a bad module never
  prevents `sm --help` from running
- `users/cli.py` and `settings/cli.py` rewritten as Click groups (the
  Typer dep is dropped from both modules)
- `[project.scripts]` entries for sm-users and sm-settings removed; each
  module now declares `[project.entry-points.simple_module_cli]` pointing
  at its Click group
- all docs (top-level README, users README, e2e-testing, scaffolded
  .env.example) updated to the new `sm <module> <command>` shape
- moved shared `logging.basicConfig(...)` into the main group callback
  so every subcommand gets it for free (subcommand call sites removed)
- test suite updated: users/tests/test_cli.py swapped from Typer's
  CliRunner to Click's

BREAKING: any script that called `sm-users create-admin` or
`sm-settings import-from-env` must now invoke `sm users create-admin`
/ `sm settings import-from-env`.
@antosubash antosubash closed this Apr 26, 2026
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.

2 participants