Skip to content

Commit 02d11ed

Browse files
authored
Merge pull request #1 from pj-simpson/textual_spike
Rip out Urwid based-TUI, replace with Textual
2 parents 3a5012d + 59a30f8 commit 02d11ed

File tree

10 files changed

+402
-374
lines changed

10 files changed

+402
-374
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CLIdat is a tool for inspecting Data from Codat.
44

55
The Command Line Interface itself is written with [Click](https://github.com/pallets/click),
66
whilst the output of the different commands is passed to
7-
a TUI from the [Pyfx](https://github.com/cielong/pyfx) package.
7+
a TUI from the [Textual](https://github.com/Textualize/textual) package.
88

99
I work in support at Codat, and have built this tool as a personal project
1010
to help with my day-job. This isn't an officially
@@ -18,17 +18,18 @@ it inside a [virtual environment](https://docs.python.org/3/library/venv.html)
1818
```console
1919
(venv) user@host:~$ pip install clidat
2020
```
21-
This software will only work on MacOS or Linux. Cygwin and WSL do not yield good results, either.
21+
Thanks to Textual, this software is cross-platform and
22+
should work well on Windows, Linux and MacOS.
2223

2324
## Quick Start
2425

2526
```console
2627
(venv) user@host:~$ clidat auth
2728
Your Codat API Key:
2829

29-
(venv) user@host:~$ clidat get-companies
30+
(venv) user@host:~$ clidat get-suppliers -id 2e14de3b-e2cf-4745-af24-a9a082b4c466
3031
```
31-
![Clidat Get Companies](./clidat_get_companies_image.png)
32+
![Clidat Get Companies](./clidat_get_suppliers_image.png)
3233

3334

3435
## Docs
@@ -52,8 +53,10 @@ flag onto the end of the command, for example:
5253
Options:
5354
--payment TEXT [required]
5455
-id, --company-id TEXT [required]
56+
-j, --json View plain JSON response
5557
--help Show this message and exit.
5658

5759

60+
5861
```
5962

clidat_get_companies_image.png

-117 KB
Binary file not shown.

clidat_get_suppliers_image.png

82.5 KB
Loading

poetry.lock

Lines changed: 147 additions & 334 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ readme = "README.md"
1010
python = "^3.10"
1111
click = "^8.1.3"
1212
pycompanydata = "^0.1.2"
13-
python-fx = "^0.2.0"
13+
textual = "^0.18.0"
1414

1515

1616
[tool.poetry.group.dev.dependencies]

src/clidat/commands/accounting.py

Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import click
2-
from pyfx import PyfxApp
32

43
from clidat.meta import (
54
company_and_connection_ids_required,
@@ -8,6 +7,8 @@
87
company_id_required_with_pagination,
98
)
109

10+
from ..tui.viewer import ViewerDispatcher
11+
1112

1213
@click.command("get-accounts")
1314
@click.pass_context
@@ -19,6 +20,7 @@ def get_accounts(
1920
page_number: int,
2021
query: str,
2122
order_by: str,
23+
json: bool = False,
2224
):
2325
client = ctx.obj
2426
accounts = client.get_accounts_page(
@@ -28,17 +30,25 @@ def get_accounts(
2830
query=query,
2931
order_by=order_by,
3032
)
31-
PyfxApp(data=accounts).run()
33+
accounts_json = accounts.json()
34+
viewer = ViewerDispatcher(
35+
data=accounts_json, json_flag=json, data_type="Chart of Accounts"
36+
)
37+
viewer()
3238

3339

3440
@click.command("get-account")
3541
@click.pass_context
3642
@click.option("--account", required=True, type=str)
3743
@company_id_required
38-
def get_account(ctx: click.Context, company_id: str, account: str):
44+
def get_account(ctx: click.Context, company_id: str, account: str, json: bool = False):
3945
client = ctx.obj
4046
account_result = client.get_account(company_id, account)
41-
PyfxApp(data=account_result).run()
47+
account_result_json = account_result.json()
48+
viewer = ViewerDispatcher(
49+
data=account_result_json, json_flag=json, data_type="Accounts"
50+
)
51+
viewer()
4252

4353

4454
@click.command("get-account-transactions")
@@ -52,6 +62,7 @@ def get_account_transactions(
5262
page_number: int,
5363
query: str,
5464
order_by: str,
65+
json: bool = False,
5566
):
5667
client = ctx.obj
5768
account_transactions = client.get_account_transactions_page(
@@ -62,21 +73,37 @@ def get_account_transactions(
6273
query=query,
6374
order_by=order_by,
6475
)
65-
PyfxApp(data=account_transactions).run()
76+
account_transactions_json = account_transactions.json()
77+
viewer = ViewerDispatcher(
78+
data=account_transactions_json,
79+
json_flag=json,
80+
data_type="List of Account Transactions",
81+
)
82+
viewer()
6683

6784

6885
@click.command("get-account-transaction")
6986
@click.pass_context
7087
@click.option("--account-transaction", required=True, type=str)
7188
@company_and_connection_ids_required
7289
def get_account_transaction(
73-
ctx: click.Context, company_id: str, connection: str, account_transaction: str
90+
ctx: click.Context,
91+
company_id: str,
92+
connection: str,
93+
account_transaction: str,
94+
json: bool = False,
7495
):
7596
client = ctx.obj
7697
account_transaction_result = client.get_account_transaction(
7798
company_id, connection, account_transaction
7899
)
79-
PyfxApp(data=account_transaction_result).run()
100+
account_transaction_result_json = account_transaction_result.json()
101+
viewer = ViewerDispatcher(
102+
data=account_transaction_result_json,
103+
json_flag=json,
104+
data_type="Account Transaction",
105+
)
106+
viewer()
80107

81108

82109
@click.command("get-bills")
@@ -89,6 +116,7 @@ def get_bills(
89116
page_number: int,
90117
query: str,
91118
order_by: str,
119+
json: bool = False,
92120
):
93121
client = ctx.obj
94122
bills = client.get_bills_page(
@@ -98,17 +126,23 @@ def get_bills(
98126
query=query,
99127
order_by=order_by,
100128
)
101-
PyfxApp(data=bills).run()
129+
bills_json = bills.json()
130+
viewer = ViewerDispatcher(
131+
data=bills_json, json_flag=json, data_type="List of Bills"
132+
)
133+
viewer()
102134

103135

104136
@click.command("get-bill")
105137
@click.pass_context
106138
@click.option("--bill", required=True, type=str)
107139
@company_id_required
108-
def get_bill(ctx: click.Context, company_id: str, bill: str):
140+
def get_bill(ctx: click.Context, company_id: str, bill: str, json: bool = False):
109141
client = ctx.obj
110142
bill_result = client.get_bill(company_id, bill)
111-
PyfxApp(data=bill_result).run()
143+
bill_result_json = bill_result.json()
144+
viewer = ViewerDispatcher(data=bill_result_json, json_flag=json, data_type="Bills")
145+
viewer()
112146

113147

114148
@click.command("get-suppliers")
@@ -121,6 +155,7 @@ def get_suppliers(
121155
page_number: int,
122156
query: str,
123157
order_by: str,
158+
json: bool = False,
124159
):
125160
client = ctx.obj
126161
suppliers = client.get_suppliers_page(
@@ -130,17 +165,27 @@ def get_suppliers(
130165
query=query,
131166
order_by=order_by,
132167
)
133-
PyfxApp(data=suppliers).run()
168+
suppliers_json = suppliers.json()
169+
viewer = ViewerDispatcher(
170+
data=suppliers_json, json_flag=json, data_type="List of Suppliers"
171+
)
172+
viewer()
134173

135174

136175
@click.command("get-supplier")
137176
@click.pass_context
138177
@click.option("--supplier", required=True, type=str)
139178
@company_id_required
140-
def get_supplier(ctx: click.Context, company_id: str, supplier: str):
179+
def get_supplier(
180+
ctx: click.Context, company_id: str, supplier: str, json: bool = False
181+
):
141182
client = ctx.obj
142183
supplier_result = client.get_supplier(company_id, supplier)
143-
PyfxApp(data=supplier_result).run()
184+
supplier_result_json = supplier_result.json()
185+
viewer = ViewerDispatcher(
186+
data=supplier_result_json, json_flag=json, data_type="Supplier"
187+
)
188+
viewer()
144189

145190

146191
@click.command("get-invoices")
@@ -153,6 +198,7 @@ def get_invoices(
153198
page_number: int,
154199
query: str,
155200
order_by: str,
201+
json: bool = False,
156202
):
157203
client = ctx.obj
158204
invoices = client.get_invoices_page(
@@ -162,17 +208,25 @@ def get_invoices(
162208
query=query,
163209
order_by=order_by,
164210
)
165-
PyfxApp(data=invoices).run()
211+
invoices_json = invoices.json()
212+
viewer = ViewerDispatcher(
213+
data=invoices_json, json_flag=json, data_type="List of Invoices"
214+
)
215+
viewer()
166216

167217

168218
@click.command("get-invoice")
169219
@click.pass_context
170220
@click.option("--invoice", required=True, type=str)
171221
@company_id_required
172-
def get_invoice(ctx: click.Context, company_id: str, invoice: str):
222+
def get_invoice(ctx: click.Context, company_id: str, invoice: str, json: bool = False):
173223
client = ctx.obj
174224
invoice_result = client.get_invoice(company_id, invoice)
175-
PyfxApp(data=invoice_result).run()
225+
invoice_result_json = invoice_result.json()
226+
viewer = ViewerDispatcher(
227+
data=invoice_result_json, json_flag=json, data_type="Invoice"
228+
)
229+
viewer()
176230

177231

178232
@click.command("get-payments")
@@ -185,6 +239,7 @@ def get_payments(
185239
page_number: int,
186240
query: str,
187241
order_by: str,
242+
json: bool = False,
188243
):
189244
client = ctx.obj
190245
payments = client.get_payment_page(
@@ -194,14 +249,22 @@ def get_payments(
194249
query=query,
195250
order_by=order_by,
196251
)
197-
PyfxApp(data=payments).run()
252+
payments_json = payments.json()
253+
viewer = ViewerDispatcher(
254+
data=payments_json, json_flag=json, data_type="List of Payments"
255+
)
256+
viewer()
198257

199258

200259
@click.command("get-payment")
201260
@click.pass_context
202261
@click.option("--payment", required=True, type=str)
203262
@company_id_required
204-
def get_payment(ctx: click.Context, company_id: str, payment: str):
263+
def get_payment(ctx: click.Context, company_id: str, payment: str, json: bool = False):
205264
client = ctx.obj
206265
payment_result = client.get_payment(company_id, payment)
207-
PyfxApp(data=payment_result).run()
266+
payment_result_json = payment_result.json()
267+
viewer = ViewerDispatcher(
268+
data=payment_result_json, json_flag=json, data_type="Payment"
269+
)
270+
viewer()

0 commit comments

Comments
 (0)