@@ -39,25 +39,36 @@ def setup() -> None:
39
39
40
40
41
41
@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 :
43
49
c = SimpleFINClient (access_url = os .getenv ("SIMPLEFIN_ACCESS_URL" ))
44
50
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
- )
58
51
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 )
61
72
62
73
63
74
# TODO: Add date range option
0 commit comments