aboutsummaryrefslogtreecommitdiffstats
path: root/firefly_cli/commands/budget.py
diff options
context:
space:
mode:
Diffstat (limited to 'firefly_cli/commands/budget.py')
-rw-r--r--firefly_cli/commands/budget.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/firefly_cli/commands/budget.py b/firefly_cli/commands/budget.py
index 990d2ad..3994958 100644
--- a/firefly_cli/commands/budget.py
+++ b/firefly_cli/commands/budget.py
@@ -2,6 +2,7 @@
import calendar
from datetime import date
from firefly_cli import registry, output
+from firefly_cli.errors import FireflyError
def _current_month():
@@ -72,3 +73,35 @@ def cmd_create(args, ctx):
resp = ctx.client.request("POST", "/api/v1/budgets", body=body)
output.emit(output.unwrap(resp), human=ctx.human)
return 0
+
+
+def _ref_arg(p):
+ p.add_argument("ref", help="budget name or id")
+
+def _delete_args(p):
+ _ref_arg(p)
+ p.add_argument("--yes", action="store_true", help="confirm deletion (required)")
+
+@registry.command("budget delete", help="delete a budget by name or id (requires --yes)", args=_delete_args)
+def cmd_delete(args, ctx):
+ if not args.yes:
+ raise FireflyError("budget delete needs --yes to confirm.")
+ b = ctx.resolver.budget(args.ref)
+ ctx.client.request("DELETE", f"/api/v1/budgets/{b['id']}")
+ output.emit({"deleted": b["id"], "name": b.get("name")}, human=ctx.human)
+ return 0
+
+def _set_active(ctx, ref, active):
+ b = ctx.resolver.budget(ref)
+ resp = ctx.client.request("PUT", f"/api/v1/budgets/{b['id']}",
+ body={"active": active})
+ output.emit(output.unwrap(resp), human=ctx.human)
+ return 0
+
+@registry.command("budget enable", help="mark a budget active", args=_ref_arg)
+def cmd_enable(args, ctx):
+ return _set_active(ctx, args.ref, True)
+
+@registry.command("budget disable", help="mark a budget inactive", args=_ref_arg)
+def cmd_disable(args, ctx):
+ return _set_active(ctx, args.ref, False)