diff options
| author | Danilo M. <danix@danix.xyz> | 2026-07-01 12:13:42 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-07-01 12:13:42 +0200 |
| commit | 941ccb2cb34944e1321b3dc23731bfa93018d74f (patch) | |
| tree | 72f5ccb1c9c0d90c320aa17dda4ddb4b8a444f40 /firefly_cli/commands/account.py | |
| parent | 60e15f9ced98c270a48d58ac000738afb78c2d7e (diff) | |
| download | firefly-cli-a84e65f1bf770d84d73eeaa37dea6a0d4297c42d.tar.gz firefly-cli-a84e65f1bf770d84d73eeaa37dea6a0d4297c42d.zip | |
feat: tx list --flat, account create --if-not-exists, --since/--until doc (v0.3.6)v0.3.6
Three smaller ISSUES.md items, one PATCH (two optional flags + a doc fix; no
existing caller or JSON shape changes).
- tx list --flat: emit one top-level object per split (journal id repeated),
dropping the transactions[] nesting so single-split journals script cleanly.
JSON-only; --human already explodes splits into a table.
- account create --if-not-exists: resolve the name first; on a clash return the
existing account with "existed": true (exit 0) instead of surfacing Firefly's
422, so import scripts are idempotent. Detects via resolver, not by parsing
the error string.
- SKILL.md documents that --since/--until filter on the transaction date (the
value date); Firefly journals have a single date field, no separate book date
(verified against firefly-iii TimeCollection setRange).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'firefly_cli/commands/account.py')
| -rw-r--r-- | firefly_cli/commands/account.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/firefly_cli/commands/account.py b/firefly_cli/commands/account.py index d78f8fc..81c2e1d 100644 --- a/firefly_cli/commands/account.py +++ b/firefly_cli/commands/account.py @@ -23,6 +23,8 @@ def _create_args(p): p.add_argument("--opening-balance", dest="opening_balance", default=None, help="initial balance (asset accounts); dated today") p.add_argument("--currency", default=None, help="currency code, e.g. EUR") + p.add_argument("--if-not-exists", dest="if_not_exists", action="store_true", + help="if an account with this name exists, return it (existed:true) instead of erroring") @registry.command("account create", help="create an asset, expense, or revenue account", args=_create_args) def cmd_create(args, ctx): @@ -30,6 +32,17 @@ def cmd_create(args, ctx): raise FireflyError( f'Unsupported account type "{args.type}". ' f'Use one of: {", ".join(_CREATE_TYPES)}.') + if getattr(args, "if_not_exists", False): + # Resolve by name to detect existence; avoids parsing Firefly's 422 + # "name already in use" error string. Missing = ResolutionError -> create. + from firefly_cli.errors import ResolutionError + try: + existing = ctx.resolver.account(args.name) + except ResolutionError: + existing = None + if existing is not None: + output.emit({**existing, "existed": True}, human=ctx.human) + return 0 body = {"name": args.name, "type": args.type} if args.type == "asset": body["account_role"] = "defaultAsset" |
