Skip to content

Commit d803cb8

Browse files
authored
Add format flag to accounts command (#9)
Closes #8
1 parent ac06539 commit d803cb8

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/simplefin/cli/__init__.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,36 @@ def setup() -> None:
3939

4040

4141
@cli.command()
42-
def accounts() -> None:
42+
@click.option(
43+
"--format",
44+
type=click.Choice(["json", "table"], case_sensitive=False),
45+
default="table",
46+
help="Specify output format",
47+
)
48+
def accounts(format: str) -> None:
4349
c = SimpleFINClient(access_url=os.getenv("SIMPLEFIN_ACCESS_URL"))
4450
accounts = c.get_accounts()
45-
table = Table(title="SimpleFIN Accounts")
46-
table.add_column("Institution")
47-
table.add_column("Account")
48-
table.add_column("Balance")
49-
table.add_column("Account ID")
50-
51-
for account in accounts:
52-
table.add_row(
53-
account["org"]["name"],
54-
account["name"],
55-
str(account["balance"]),
56-
account["id"],
57-
)
5851

59-
console = Console()
60-
console.print(table)
52+
if format == "json":
53+
console = Console()
54+
console.print(json.dumps(accounts, indent=4, cls=DateTimeEncoder))
55+
else:
56+
table = Table(title="SimpleFIN Accounts")
57+
table.add_column("Institution")
58+
table.add_column("Account")
59+
table.add_column("Balance")
60+
table.add_column("Account ID")
61+
62+
for account in accounts:
63+
table.add_row(
64+
account["org"]["name"],
65+
account["name"],
66+
str(account["balance"]),
67+
account["id"],
68+
)
69+
70+
console = Console()
71+
console.print(table)
6172

6273

6374
# TODO: Add date range option

0 commit comments

Comments
 (0)