feat(cli): global flags after the subcommand (AWS-CLI style) — RFC, do not merge#59
Closed
phitoduck wants to merge 1 commit into
Closed
feat(cli): global flags after the subcommand (AWS-CLI style) — RFC, do not merge#59phitoduck wants to merge 1 commit into
phitoduck wants to merge 1 commit into
Conversation
Moves --output, --log-level, --config-file, --user-id, … off the root callback onto each subcommand via a shared `_global_options` decorator, so users can write `loseit search "tortilla" -o json` instead of `loseit -o json search "tortilla"`. The per-flag definitions live in one place; new subcommands opt in with a single line. Login's local `--user-name` and `config_file` Python var collided with the decorator's set: dropped the local --user-name (now routed through ctx.obj["config_overrides"]["user_name"] — same UX, same flag), and renamed `config_file` → `write_config_to` (CLI flag --write-config-to unchanged).
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.
Draft / RFC — not for merge. Opened on request to evaluate what the per-subcommand decorator approach actually looks like for moving
--output(and friends) to after the subcommand name.Summary
--output,--log-level,--config-file,--user-id,--user-name,--hours-from-gmt,--policy-hash,--strong-name,--log-file,--log-headers) from the root@app.callback()._global_optionsdecorator (src/lose_it/cli.py:179) that mutates a Typer command's signature to append the same set oftyper.Options. The per-flag definitions live in one place (_GLOBAL_OPT_SPECS).@_global_optionsline. Subcommand bodies are unchanged — the decorator stashes everything onctx.objin the shape_open_loseitalready expects.logincouldn't take the decorator clean because of two name collisions:--user-nameflag → dropped; login now reads the override fromctx.obj["config_overrides"]["user_name"]. Same UX, same flag.config_filePython var → renamed towrite_config_to. CLI flag--write-config-tounchanged.What this lets users do
…instead of having
-o jsonglued to the front of every command.Gotcha worth knowing
from __future__ import annotationsis on at the top ofcli.py, so every parameter annotation arrives at the decorator as a string. Withoutinspect.signature(func, eval_str=True)thetyper.Argument(...)metadata stays unresolved and every positional argument silently degrades into a--query-style option. Comment on the decorator calls that out.Trade-offs vs the argv-pre-parse alternative
--helplisting on each subcommand —loseit search --helpshows--output,--log-level, etc.--helpis now ~3× longer (one block per global). On wide terminals it's fine; on narrow ones it wraps a lot.--user-namecollision). Same flag and same UX, but the route throughctx.objis slightly indirect.loseit -o json search foo(the current style) stops working. That's the whole point, but it's a hard break for anyone relying on the old position.Test plan
uv run pytest— 165 passed, 5 deselectedloseit version -o json,loseit search --helpshows the new global block