aboutsummaryrefslogtreecommitdiffstats
path: root/cli/src/commands/accounts.ts
diff options
context:
space:
mode:
authorivar <i@oiee.no>2026-03-09 23:05:38 +0100
committerivar <i@oiee.no>2026-03-09 23:05:38 +0100
commit69448e29a85cad3a94b3be3ad33efbc52764528f (patch)
treec32b8c817322fdf26edbbb3fa75b9505a7020ae8 /cli/src/commands/accounts.ts
parentb35302fa020ec82a9d67a6cb34379d42983d3cfc (diff)
downloadsparebank1-actualbudget-master.tar.xz
sparebank1-actualbudget-master.zip
Add wip cliHEADmaster
Diffstat (limited to 'cli/src/commands/accounts.ts')
-rw-r--r--cli/src/commands/accounts.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/cli/src/commands/accounts.ts b/cli/src/commands/accounts.ts
new file mode 100644
index 0000000..4b7e980
--- /dev/null
+++ b/cli/src/commands/accounts.ts
@@ -0,0 +1,46 @@
+import * as p from "@clack/prompts"
+import { loadConfig, saveConfig } from "../config"
+import { createSb1Client } from "../sb1"
+import { getAccounts } from "../actual"
+
+export async function accounts() {
+ const config = loadConfig()
+ const sb1 = createSb1Client(config.sb1)
+
+ const spinner = p.spinner()
+ spinner.start("Fetching accounts...")
+ const [sb1Accounts, actualAccounts] = await Promise.all([
+ sb1.getAccounts(),
+ getAccounts(config.actual)
+ ])
+ spinner.stop("Accounts loaded.")
+
+ const openActualAccounts = actualAccounts.filter(a => !a.closed)
+
+ p.intro("Account mappings")
+
+ const mappings = []
+ for (const sb1Account of sb1Accounts) {
+ const existing = config.mappings.find(m => m.sb1Id === sb1Account.key)
+
+ const actualId = await p.select({
+ message: `${sb1Account.name} (${sb1Account.balance} ${sb1Account.currencyCode})`,
+ options: [
+ { value: null, label: "Skip" },
+ ...openActualAccounts.map(a => ({ value: a.id, label: a.name }))
+ ],
+ initialValue: existing?.actualId ?? null,
+ })
+
+ if (p.isCancel(actualId)) {
+ p.cancel("Cancelled.")
+ process.exit(0)
+ }
+
+ if (actualId) mappings.push({ sb1Id: sb1Account.key, actualId, label: sb1Account.name })
+ }
+
+ saveConfig({ ...config, mappings })
+
+ p.outro(`Saved ${mappings.length} mapping(s).`)
+}