Skip to content

Commit c0778dd

Browse files
committed
fixes #4
1 parent 7975319 commit c0778dd

File tree

4 files changed

+126
-1
lines changed

4 files changed

+126
-1
lines changed

fasthtml/_modidx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'lib_path': 'fasthtml'},
88
'syms': { 'fasthtml.all': {},
99
'fasthtml.authmw': {},
10-
'fasthtml.cli': {},
10+
'fasthtml.cli': {'fasthtml.cli.railway_link': ('cli.html#railway_link', 'fasthtml/cli.py')},
1111
'fasthtml.components': { 'fasthtml.components._FindElems': ('components.html#_findelems', 'fasthtml/components.py'),
1212
'fasthtml.components._FindElems.__init__': ( 'components.html#_findelems.__init__',
1313
'fasthtml/components.py'),

fasthtml/cli.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/04_cli.ipynb.
2+
3+
# %% auto 0
4+
__all__ = ['railway_link']
5+
6+
# %% ../nbs/04_cli.ipynb 1
7+
from fastcore.utils import *
8+
from fastcore.script import call_parse
9+
import json
10+
from subprocess import run
11+
12+
# %% ../nbs/04_cli.ipynb 2
13+
@call_parse
14+
def railway_link():
15+
t = run("railway status --json".split(), capture_output=True)
16+
print(t.stdout.decode())
17+
j = json.loads(t.stdout)
18+
prj = j['id']
19+
idxpath = 'edges', 0, 'node', 'id'
20+
env = nested_idx(j, 'environments', *idxpath)
21+
svc = nested_idx(j, 'services', *idxpath)
22+
23+
cmd = f"railway link -e {env} -p {prj} -s {svc}"
24+
print(cmd)
25+
res = run(cmd.split(), capture_output=True)

nbs/04_cli.ipynb

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "b73068da",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"#| default_exp cli"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 15,
16+
"id": "acfbc502",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"#| export\n",
21+
"from fastcore.utils import *\n",
22+
"from fastcore.script import call_parse\n",
23+
"import json\n",
24+
"from subprocess import run"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": null,
30+
"id": "11d71cfc",
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"#| export\n",
35+
"@call_parse\n",
36+
"def railway_link():\n",
37+
" t = run(\"railway status --json\".split(), capture_output=True)\n",
38+
" j = json.loads(t.stdout)\n",
39+
" prj = j['id']\n",
40+
" idxpath = 'edges', 0, 'node', 'id'\n",
41+
" env = nested_idx(j, 'environments', *idxpath)\n",
42+
" svc = nested_idx(j, 'services', *idxpath)\n",
43+
"\n",
44+
" cmd = f\"railway link -e {env} -p {prj} -s {svc}\"\n",
45+
" res = run(cmd.split(), capture_output=True)"
46+
]
47+
},
48+
{
49+
"cell_type": "markdown",
50+
"id": "474e14b4",
51+
"metadata": {},
52+
"source": [
53+
"## Export -"
54+
]
55+
},
56+
{
57+
"cell_type": "code",
58+
"execution_count": 24,
59+
"id": "d211e8e2",
60+
"metadata": {},
61+
"outputs": [],
62+
"source": [
63+
"#|hide\n",
64+
"import nbdev; nbdev.nbdev_export()"
65+
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": null,
70+
"id": "7b1d43a0",
71+
"metadata": {},
72+
"outputs": [],
73+
"source": []
74+
}
75+
],
76+
"metadata": {
77+
"kernelspec": {
78+
"display_name": "Python 3 (ipykernel)",
79+
"language": "python",
80+
"name": "python3"
81+
},
82+
"language_info": {
83+
"codemirror_mode": {
84+
"name": "ipython",
85+
"version": 3
86+
},
87+
"file_extension": ".py",
88+
"mimetype": "text/x-python",
89+
"name": "python",
90+
"nbconvert_exporter": "python",
91+
"pygments_lexer": "ipython3",
92+
"version": "3.11.8"
93+
}
94+
},
95+
"nbformat": 4,
96+
"nbformat_minor": 5
97+
}

settings.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ description = The fastest way to create an HTML app
2828
keywords = nbdev jupyter notebook python
2929
language = English
3030
status = 3
31+
32+
console_scripts = fh_railway_link=fasthtml.cli:railway_link
33+
3134
user = AnswerDotAI
3235
readme_nb = index.ipynb
3336
allowed_metadata_keys =

0 commit comments

Comments
 (0)