feat(cli): add --version, colorize errors, migrate sm-settings to Typer - #59
Closed
antosubash wants to merge 3 commits into
Closed
antosubash wants to merge 3 commits into
antosubash wants to merge 3 commits into
Conversation
- 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`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Polishes the three console scripts (
sm,sm-users,sm-settings) so they behave consistently and give readable feedback:--version/-Von all three. None of them exposed a version flag before; they all resolve it fromimportlib.metadata(falls back to"unknown"when the package isn't installed, so it's safe in dev checkouts).smandsm-users.ERROR:/WARNING:prefixes now render red/yellow viaclick.secho/typer.secho, and success messages render green. No behavioral changes — exit codes and message substrings are preserved.sm-settingsswapped its hand-rolled argv parser for a Typer app. The oldmain()was ~30 lines of manualsys.argv[1:]juggling with a bareprint()for help and"Unknown command:"for anything else. It now gets real--help, real subcommand dispatch, and shell-completion scaffolding for free, matching thesm-usersstyle.import_from_env_implis unchanged, so the existing tests (which import it directly) continue to pass. Addedtyper>=0.12tomodules/settings/pyproject.tomldependencies.-heverywhere.help_option_namesis set on all three so-hworks as an alias for--help.smCLI docstrings to keep the file under the repo's 300-line cap after the additions.Test plan
uv run pytest --no-header -q— 977 passeduv run ruff check+uv run ruff format --checkon the three CLI files — cleanuv run python scripts/check_file_size.py— OK: no files exceed 300 linesuv run sm --version,uv run sm-users --version,uv run sm-settings --version— all print<name> 0.0.1uv run sm --help,sm-users --help,sm-settings --help— render; Typer shows rich-formatted helphttps://claude.ai/code/session_01UZwR7S8JzFtWSSArVbzF7A
Generated by Claude Code