diff options
| author | Danilo M. <danix@danix.xyz> | 2026-07-01 11:02:32 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-07-01 11:02:32 +0200 |
| commit | 238a4506cfeda388d097265b133004b63f130de6 (patch) | |
| tree | 6d87a628df3472e3583b6dabedd3b611ab799edf | |
| parent | 1c807048f8c754b421dae5a07ee8c053e3788348 (diff) | |
| download | firefly-cli-0.3.4.tar.gz firefly-cli-0.3.4.zip | |
feat: completion suggests --type values per commandv0.3.4
Tab-completing --type now offers the valid values instead of nothing:
account list -> asset/expense/revenue/liability, account create ->
asset/expense/revenue, tx add/edit -> withdrawal/deposit/transfer. Keyed per
command off a static FLAG_VALUES map in gen_completion.py (types are a fixed
Firefly enum, so no API call in the completion). Partial input filters and
unrelated flags still complete normally.
Completion-only: no CLI/JSON/exit change, ships under v0.3.4.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| -rw-r--r-- | TODO.md | 4 | ||||
| -rw-r--r-- | completions/firefly.bash | 14 | ||||
| -rw-r--r-- | scripts/gen_completion.py | 30 |
3 files changed, 47 insertions, 1 deletions
@@ -29,4 +29,6 @@ bash completion). - [ ] zsh / fish completion (bash done). ## UI/UX -- [ ] completion needs to suggest based on `--type`. EG, `firefly --human account list --type` should suggest available account types. +- [x] completion suggests values for `--type` (account: asset/expense/revenue + /liability, tx: withdrawal/deposit/transfer), keyed per command. Static + enum, no API call. See `FLAG_VALUES` in `scripts/gen_completion.py`. diff --git a/completions/firefly.bash b/completions/firefly.bash index 68c4b74..648fbe0 100644 --- a/completions/firefly.bash +++ b/completions/firefly.bash @@ -56,6 +56,20 @@ _firefly() { tx) leaves="add delete edit get list search";; esac + # Flag values: when the previous word is a flag with a fixed value set for + # this command, suggest those values instead of more flags. + local vals="" + case "$group $leaf $prev" in + "account create --type") vals="asset expense revenue";; + "account list --type") vals="asset expense revenue liability";; + "tx add --type") vals="withdrawal deposit transfer";; + "tx edit --type") vals="withdrawal deposit transfer";; + esac + if [[ -n $vals ]]; then + COMPREPLY=($(compgen -W "$vals" -- "$cur")) + return + fi + if [[ -z $group ]]; then COMPREPLY=($(compgen -W "$groups $global_opts" -- "$cur")) elif [[ -z $leaf ]]; then diff --git a/scripts/gen_completion.py b/scripts/gen_completion.py index 4714bf1..cee7d8e 100644 --- a/scripts/gen_completion.py +++ b/scripts/gen_completion.py @@ -21,6 +21,16 @@ import firefly_cli.commands # noqa: F401 triggers registration GROUP_ORDER = ["auth", "account", "category", "tag", "tx"] +# Static value suggestions for flags whose choices are a fixed enum, keyed on +# "<group leaf>" then flag. Account/transaction types are fixed in Firefly, so +# no API call is needed (a completion must not hit the network). +FLAG_VALUES = { + "account list": {"--type": "asset expense revenue liability"}, + "account create": {"--type": "asset expense revenue"}, + "tx add": {"--type": "withdrawal deposit transfer"}, + "tx edit": {"--type": "withdrawal deposit transfer"}, +} + def collect(): groups = defaultdict(dict) # group -> {leaf: [--flag, ...]} @@ -51,10 +61,19 @@ def render(groups): leaf_cases.append( f' "{g} {leaf}")'.ljust(28) + f'leaf_opts="{flags}";;') + # Per-command flag-value cases: "<group leaf> <flag>") vals="..." + value_cases = [] + for cmd in sorted(FLAG_VALUES): + for flag in sorted(FLAG_VALUES[cmd]): + vals = FLAG_VALUES[cmd][flag] + value_cases.append(f' "{cmd} {flag}")'.ljust(34) + + f'vals="{vals}";;') + return TEMPLATE.format( groups=" ".join(order), leaf_cases="\n".join(leaf_cases), group_cases="\n".join(group_cases), + value_cases="\n".join(value_cases), ) @@ -105,6 +124,17 @@ _firefly() {{ {group_cases} esac + # Flag values: when the previous word is a flag with a fixed value set for + # this command, suggest those values instead of more flags. + local vals="" + case "$group $leaf $prev" in +{value_cases} + esac + if [[ -n $vals ]]; then + COMPREPLY=($(compgen -W "$vals" -- "$cur")) + return + fi + if [[ -z $group ]]; then COMPREPLY=($(compgen -W "$groups $global_opts" -- "$cur")) elif [[ -z $leaf ]]; then |
