aboutsummaryrefslogtreecommitdiffstats
path: root/firefly_cli
diff options
context:
space:
mode:
Diffstat (limited to 'firefly_cli')
-rw-r--r--firefly_cli/commands/budget.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/firefly_cli/commands/budget.py b/firefly_cli/commands/budget.py
index 257bba7..990d2ad 100644
--- a/firefly_cli/commands/budget.py
+++ b/firefly_cli/commands/budget.py
@@ -41,3 +41,34 @@ def cmd_list(args, ctx):
rows = [{**r, "spent": _spent_scalar(r)} for r in rows]
output.emit(rows, human=ctx.human)
return 0
+
+
+def _create_args(p):
+ p.add_argument("name", help="budget name (must be unique)")
+ g = p.add_mutually_exclusive_group()
+ g.add_argument("--active", dest="active", action="store_true", default=True,
+ help="create active (default)")
+ g.add_argument("--inactive", dest="active", action="store_false",
+ help="create inactive")
+ p.add_argument("--currency", default=None, help="auto-budget currency code, e.g. EUR")
+ p.add_argument("--auto-budget-amount", dest="auto_budget_amount", default=None,
+ help="recurring auto-budget amount")
+ p.add_argument("--auto-budget-period", dest="auto_budget_period", default=None,
+ help="daily|weekly|monthly|quarterly|half_year|yearly")
+ p.add_argument("--auto-budget-type", dest="auto_budget_type", default=None,
+ help="reset|rollover|adjusted|none")
+
+@registry.command("budget create", help="create a budget", args=_create_args)
+def cmd_create(args, ctx):
+ body = {"name": args.name, "active": args.active}
+ if args.auto_budget_amount is not None:
+ body["auto_budget_amount"] = str(args.auto_budget_amount)
+ if args.auto_budget_period is not None:
+ body["auto_budget_period"] = args.auto_budget_period
+ if args.auto_budget_type is not None:
+ body["auto_budget_type"] = args.auto_budget_type
+ if args.currency:
+ body["currency_code"] = args.currency
+ resp = ctx.client.request("POST", "/api/v1/budgets", body=body)
+ output.emit(output.unwrap(resp), human=ctx.human)
+ return 0