aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--SKILL.md4
-rw-r--r--firefly_cli/__init__.py2
-rw-r--r--firefly_cli/commands/transaction.py7
-rw-r--r--pyproject.toml2
-rw-r--r--tests/unit/test_commands_transaction.py48
5 files changed, 61 insertions, 2 deletions
diff --git a/SKILL.md b/SKILL.md
index e34f160..4cf40bb 100644
--- a/SKILL.md
+++ b/SKILL.md
@@ -92,6 +92,10 @@ firefly tx add 1800 --from Salary --to test01 --desc "June pay"
```bash
firefly tx add 200 --from test01 --to Savings --type transfer
```
+For a transfer, `tx add` echoes `transfer: <from> → <to>, <amount>` to stderr
+before writing (also in `--dry-run`) so a swapped `--from`/`--to` is caught
+before it silently drifts balances by 2x the amount. stdout JSON is unchanged;
+the hint is on stderr only.
**Create an account** (when `tx add` errors that an account does not exist,
and the user confirms it should be created):
diff --git a/firefly_cli/__init__.py b/firefly_cli/__init__.py
index b7a8764..4b170ef 100644
--- a/firefly_cli/__init__.py
+++ b/firefly_cli/__init__.py
@@ -2,4 +2,4 @@
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
# Licensed under the GNU General Public License v2.0 only.
-__version__ = "0.3.4"
+__version__ = "0.3.5"
diff --git a/firefly_cli/commands/transaction.py b/firefly_cli/commands/transaction.py
index 8d858b6..df1ffc4 100644
--- a/firefly_cli/commands/transaction.py
+++ b/firefly_cli/commands/transaction.py
@@ -54,6 +54,13 @@ def cmd_add(args, ctx):
split["category_name"] = args.category
if args.tags:
split["tags"] = [t.strip() for t in args.tags.split(",") if t.strip()]
+ if ttype == "transfer":
+ # Transfer direction is easy to reverse silently (ISSUES.md #5); echo it
+ # to stderr so the user/agent can catch a swapped --from/--to. stdout
+ # JSON unchanged; shown for both real writes and --dry-run.
+ import sys
+ print(f'transfer: {src["name"]} → {dst["name"]}, {split["amount"]}',
+ file=sys.stderr)
if args.dry_run:
# Accounts already resolved above (missing name = hard error). Write nothing.
# dry-run wins over skip-dupes: caller wants a preview, not a write.
diff --git a/pyproject.toml b/pyproject.toml
index 91e78c0..7e1dbcd 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "firefly-iii-agent"
-version = "0.3.4"
+version = "0.3.5"
description = "CLI tool for agent interaction with Firefly III"
readme = "README.md"
requires-python = ">=3.11"
diff --git a/tests/unit/test_commands_transaction.py b/tests/unit/test_commands_transaction.py
index 13d6469..0fa02ac 100644
--- a/tests/unit/test_commands_transaction.py
+++ b/tests/unit/test_commands_transaction.py
@@ -134,6 +134,54 @@ class TestTxAdd(unittest.TestCase):
self.assertEqual(client.request.call_args[0][:2],
("POST", "/api/v1/transactions"))
+ def test_transfer_prints_direction_hint_to_stderr(self):
+ import io
+ from contextlib import redirect_stderr
+ ctx, client, resolver = make_ctx()
+ resolver.account.side_effect = lambda n: {
+ "BBVA": {"id": "3", "name": "BBVA", "type": "asset"},
+ "Medio": {"id": "4", "name": "Medio", "type": "asset"},
+ }[n]
+ client.request.return_value = {"data": {"id": "1", "attributes": {}}}
+ args = MagicMock(amount="100", source="BBVA", dest="Medio", desc=None,
+ date=None, category=None, tags=None, type=None,
+ dry_run=False, skip_dupes=False)
+ buf = io.StringIO()
+ with redirect_stderr(buf):
+ tx.cmd_add(args, ctx)
+ self.assertIn("transfer: BBVA → Medio, 100", buf.getvalue())
+
+ def test_transfer_hint_shown_in_dry_run(self):
+ import io
+ from contextlib import redirect_stderr
+ ctx, client, resolver = make_ctx()
+ resolver.account.side_effect = lambda n: {"id": "1", "type": "asset", "name": n}
+ args = MagicMock(amount="5", source="A", dest="B", desc=None, date=None,
+ category=None, tags=None, type="transfer",
+ dry_run=True, skip_dupes=False)
+ buf = io.StringIO()
+ with redirect_stderr(buf):
+ tx.cmd_add(args, ctx)
+ self.assertIn("transfer: A → B, 5", buf.getvalue())
+ client.request.assert_not_called()
+
+ def test_withdrawal_no_direction_hint(self):
+ import io
+ from contextlib import redirect_stderr
+ ctx, client, resolver = make_ctx()
+ resolver.account.side_effect = lambda n: {
+ "Checking": {"id": "1", "name": "Checking", "type": "asset"},
+ "Groceries": {"id": "2", "name": "Groceries", "type": "expense"},
+ }[n]
+ client.request.return_value = {"data": {"id": "1", "attributes": {}}}
+ args = MagicMock(amount="5", source="Checking", dest="Groceries", desc=None,
+ date=None, category=None, tags=None, type=None,
+ dry_run=False, skip_dupes=False)
+ buf = io.StringIO()
+ with redirect_stderr(buf):
+ tx.cmd_add(args, ctx)
+ self.assertNotIn("transfer:", buf.getvalue())
+
def test_dry_run_beats_skip_dupes_no_search(self):
ctx, client, resolver = make_ctx()
resolver.account.side_effect = lambda n: {"id": "1", "type": "asset", "name": n}