@@ -29,37 +29,37 @@ def __init__(self):
29
29
def compose (self ) -> ComposeResult :
30
30
"""Create child widgets for the app."""
31
31
yield Header ()
32
-
32
+
33
33
if not self .organizations :
34
34
yield Container (
35
- Static ("⚠️ No organizations found. Please run 'codegen login' first." , classes = "warning-message" ),
35
+ Static ("⚠️ No organizations found. Please run 'codegen login' first." , classes = "warning-message" ),
36
36
id = "no-orgs-warning"
37
37
)
38
38
else :
39
39
with Vertical ():
40
40
yield Static ("🏢 Select Your Organization" , classes = "title" )
41
41
yield Static ("Use ↑↓ to navigate, Enter to select, Q/Esc to quit" , classes = "help" )
42
-
42
+
43
43
table = DataTable (id = "orgs-table" , cursor_type = "row" )
44
44
table .add_columns ("Current" , "ID" , "Organization Name" )
45
-
45
+
46
46
# Get the actual current org ID (checks environment variables first)
47
47
actual_current_org_id = resolve_org_id ()
48
-
48
+
49
49
for org in self .organizations :
50
50
org_id = org ["id" ]
51
51
org_name = org ["name" ]
52
52
is_current = "●" if org_id == actual_current_org_id else " "
53
-
53
+
54
54
table .add_row (is_current , str (org_id ), org_name , key = str (org_id ))
55
-
55
+
56
56
yield table
57
-
57
+
58
58
yield Static (
59
- "\n 💡 Selecting an organization will update your CODEGEN_ORG_ID environment variable." ,
59
+ "\n 💡 Selecting an organization will update your CODEGEN_ORG_ID environment variable." ,
60
60
classes = "help"
61
61
)
62
-
62
+
63
63
yield Footer ()
64
64
65
65
def on_mount (self ) -> None :
@@ -89,7 +89,7 @@ def _handle_org_selection(self) -> None:
89
89
90
90
try :
91
91
table = self .query_one ("#orgs-table" , DataTable )
92
-
92
+
93
93
if table .cursor_row is not None and table .cursor_row < len (self .organizations ):
94
94
# Get the selected organization directly from the cursor position
95
95
selected_org = self .organizations [table .cursor_row ]
@@ -106,24 +106,24 @@ def _set_organization(self, org_id: int, org_name: str) -> None:
106
106
"""Set the selected organization as default."""
107
107
# Set environment variable
108
108
os .environ ["CODEGEN_ORG_ID" ] = str (org_id )
109
-
109
+
110
110
# Try to update .env file
111
111
env_updated = self ._update_env_file (org_id )
112
-
112
+
113
113
if env_updated :
114
114
self .notify (f"✓ Set default organization: { org_name } (ID: { org_id } )" )
115
115
self .notify ("✓ Updated .env file with CODEGEN_ORG_ID" )
116
116
else :
117
117
self .notify (f"✓ Set organization: { org_name } (ID: { org_id } )" )
118
118
self .notify ("ℹ Add 'export CODEGEN_ORG_ID={org_id}' to your shell for persistence" )
119
-
119
+
120
120
# Wait a moment for user to see the notifications, then close
121
121
self .set_timer (2.0 , self ._close_screen )
122
122
123
123
def _update_env_file (self , org_id : int ) -> bool :
124
124
"""Update the .env file with the new organization ID."""
125
125
env_file_path = ".env"
126
-
126
+
127
127
try :
128
128
lines = []
129
129
key_found = False
@@ -152,9 +152,9 @@ def _update_env_file(self, org_id: int) -> bool:
152
152
# Write back to file
153
153
with open (env_file_path , "w" ) as f :
154
154
f .writelines (lines )
155
-
155
+
156
156
return True
157
-
157
+
158
158
except Exception :
159
159
return False
160
160
@@ -174,7 +174,7 @@ def action_quit(self) -> None:
174
174
175
175
class OrgSelectorApp (App ):
176
176
"""Standalone app wrapper for the organization selector."""
177
-
177
+
178
178
CSS_PATH = "../../tui/codegen_theme.tcss" # Use custom Codegen theme
179
179
TITLE = "Organization Selector - Codegen CLI"
180
180
BINDINGS = [
@@ -191,37 +191,37 @@ def __init__(self):
191
191
def compose (self ) -> ComposeResult :
192
192
"""Create child widgets for the app."""
193
193
yield Header ()
194
-
194
+
195
195
if not self .organizations :
196
196
yield Container (
197
- Static ("⚠️ No organizations found. Please run 'codegen login' first." , classes = "warning-message" ),
197
+ Static ("⚠️ No organizations found. Please run 'codegen login' first." , classes = "warning-message" ),
198
198
id = "no-orgs-warning"
199
199
)
200
200
else :
201
201
with Vertical ():
202
202
yield Static ("🏢 Select Your Organization" , classes = "title" )
203
203
yield Static ("Use ↑↓ to navigate, Enter to select, Q/Esc to quit" , classes = "help" )
204
-
204
+
205
205
table = DataTable (id = "orgs-table" , cursor_type = "row" )
206
206
table .add_columns ("Current" , "ID" , "Organization Name" )
207
-
207
+
208
208
# Get the actual current org ID (checks environment variables first)
209
209
actual_current_org_id = resolve_org_id ()
210
-
210
+
211
211
for org in self .organizations :
212
212
org_id = org ["id" ]
213
213
org_name = org ["name" ]
214
214
is_current = "●" if org_id == actual_current_org_id else " "
215
-
215
+
216
216
table .add_row (is_current , str (org_id ), org_name , key = str (org_id ))
217
-
217
+
218
218
yield table
219
-
219
+
220
220
yield Static (
221
- "\n 💡 Selecting an organization will update your CODEGEN_ORG_ID environment variable." ,
221
+ "\n 💡 Selecting an organization will update your CODEGEN_ORG_ID environment variable." ,
222
222
classes = "help"
223
223
)
224
-
224
+
225
225
yield Footer ()
226
226
227
227
def on_mount (self ) -> None :
@@ -251,7 +251,7 @@ def _handle_org_selection(self) -> None:
251
251
252
252
try :
253
253
table = self .query_one ("#orgs-table" , DataTable )
254
-
254
+
255
255
if table .cursor_row is not None and table .cursor_row < len (self .organizations ):
256
256
# Get the selected organization directly from the cursor position
257
257
selected_org = self .organizations [table .cursor_row ]
@@ -268,24 +268,24 @@ def _set_organization(self, org_id: int, org_name: str) -> None:
268
268
"""Set the selected organization as default."""
269
269
# Set environment variable
270
270
os .environ ["CODEGEN_ORG_ID" ] = str (org_id )
271
-
271
+
272
272
# Try to update .env file
273
273
env_updated = self ._update_env_file (org_id )
274
-
274
+
275
275
if env_updated :
276
276
self .notify (f"✓ Set default organization: { org_name } (ID: { org_id } )" )
277
277
self .notify ("✓ Updated .env file with CODEGEN_ORG_ID" )
278
278
else :
279
279
self .notify (f"✓ Set organization: { org_name } (ID: { org_id } )" )
280
280
self .notify ("ℹ Add 'export CODEGEN_ORG_ID={org_id}' to your shell for persistence" )
281
-
281
+
282
282
# Wait a moment for user to see the notifications, then exit
283
283
self .set_timer (2.0 , self .exit )
284
284
285
285
def _update_env_file (self , org_id : int ) -> bool :
286
286
"""Update the .env file with the new organization ID."""
287
287
env_file_path = ".env"
288
-
288
+
289
289
try :
290
290
lines = []
291
291
key_found = False
@@ -314,9 +314,9 @@ def _update_env_file(self, org_id: int) -> bool:
314
314
# Write back to file
315
315
with open (env_file_path , "w" ) as f :
316
316
f .writelines (lines )
317
-
317
+
318
318
return True
319
-
319
+
320
320
except Exception :
321
321
return False
322
322
0 commit comments