@@ -29,37 +29,37 @@ def __init__(self):
2929 def compose (self ) -> ComposeResult :
3030 """Create child widgets for the app."""
3131 yield Header ()
32-
32+
3333 if not self .organizations :
3434 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" ),
3636 id = "no-orgs-warning"
3737 )
3838 else :
3939 with Vertical ():
4040 yield Static ("🏢 Select Your Organization" , classes = "title" )
4141 yield Static ("Use ↑↓ to navigate, Enter to select, Q/Esc to quit" , classes = "help" )
42-
42+
4343 table = DataTable (id = "orgs-table" , cursor_type = "row" )
4444 table .add_columns ("Current" , "ID" , "Organization Name" )
45-
45+
4646 # Get the actual current org ID (checks environment variables first)
4747 actual_current_org_id = resolve_org_id ()
48-
48+
4949 for org in self .organizations :
5050 org_id = org ["id" ]
5151 org_name = org ["name" ]
5252 is_current = "●" if org_id == actual_current_org_id else " "
53-
53+
5454 table .add_row (is_current , str (org_id ), org_name , key = str (org_id ))
55-
55+
5656 yield table
57-
57+
5858 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." ,
6060 classes = "help"
6161 )
62-
62+
6363 yield Footer ()
6464
6565 def on_mount (self ) -> None :
@@ -89,7 +89,7 @@ def _handle_org_selection(self) -> None:
8989
9090 try :
9191 table = self .query_one ("#orgs-table" , DataTable )
92-
92+
9393 if table .cursor_row is not None and table .cursor_row < len (self .organizations ):
9494 # Get the selected organization directly from the cursor position
9595 selected_org = self .organizations [table .cursor_row ]
@@ -106,24 +106,24 @@ def _set_organization(self, org_id: int, org_name: str) -> None:
106106 """Set the selected organization as default."""
107107 # Set environment variable
108108 os .environ ["CODEGEN_ORG_ID" ] = str (org_id )
109-
109+
110110 # Try to update .env file
111111 env_updated = self ._update_env_file (org_id )
112-
112+
113113 if env_updated :
114114 self .notify (f"✓ Set default organization: { org_name } (ID: { org_id } )" )
115115 self .notify ("✓ Updated .env file with CODEGEN_ORG_ID" )
116116 else :
117117 self .notify (f"✓ Set organization: { org_name } (ID: { org_id } )" )
118118 self .notify ("ℹ Add 'export CODEGEN_ORG_ID={org_id}' to your shell for persistence" )
119-
119+
120120 # Wait a moment for user to see the notifications, then close
121121 self .set_timer (2.0 , self ._close_screen )
122122
123123 def _update_env_file (self , org_id : int ) -> bool :
124124 """Update the .env file with the new organization ID."""
125125 env_file_path = ".env"
126-
126+
127127 try :
128128 lines = []
129129 key_found = False
@@ -152,9 +152,9 @@ def _update_env_file(self, org_id: int) -> bool:
152152 # Write back to file
153153 with open (env_file_path , "w" ) as f :
154154 f .writelines (lines )
155-
155+
156156 return True
157-
157+
158158 except Exception :
159159 return False
160160
@@ -174,7 +174,7 @@ def action_quit(self) -> None:
174174
175175class OrgSelectorApp (App ):
176176 """Standalone app wrapper for the organization selector."""
177-
177+
178178 CSS_PATH = "../../tui/codegen_theme.tcss" # Use custom Codegen theme
179179 TITLE = "Organization Selector - Codegen CLI"
180180 BINDINGS = [
@@ -191,37 +191,37 @@ def __init__(self):
191191 def compose (self ) -> ComposeResult :
192192 """Create child widgets for the app."""
193193 yield Header ()
194-
194+
195195 if not self .organizations :
196196 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" ),
198198 id = "no-orgs-warning"
199199 )
200200 else :
201201 with Vertical ():
202202 yield Static ("🏢 Select Your Organization" , classes = "title" )
203203 yield Static ("Use ↑↓ to navigate, Enter to select, Q/Esc to quit" , classes = "help" )
204-
204+
205205 table = DataTable (id = "orgs-table" , cursor_type = "row" )
206206 table .add_columns ("Current" , "ID" , "Organization Name" )
207-
207+
208208 # Get the actual current org ID (checks environment variables first)
209209 actual_current_org_id = resolve_org_id ()
210-
210+
211211 for org in self .organizations :
212212 org_id = org ["id" ]
213213 org_name = org ["name" ]
214214 is_current = "●" if org_id == actual_current_org_id else " "
215-
215+
216216 table .add_row (is_current , str (org_id ), org_name , key = str (org_id ))
217-
217+
218218 yield table
219-
219+
220220 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." ,
222222 classes = "help"
223223 )
224-
224+
225225 yield Footer ()
226226
227227 def on_mount (self ) -> None :
@@ -251,7 +251,7 @@ def _handle_org_selection(self) -> None:
251251
252252 try :
253253 table = self .query_one ("#orgs-table" , DataTable )
254-
254+
255255 if table .cursor_row is not None and table .cursor_row < len (self .organizations ):
256256 # Get the selected organization directly from the cursor position
257257 selected_org = self .organizations [table .cursor_row ]
@@ -268,24 +268,24 @@ def _set_organization(self, org_id: int, org_name: str) -> None:
268268 """Set the selected organization as default."""
269269 # Set environment variable
270270 os .environ ["CODEGEN_ORG_ID" ] = str (org_id )
271-
271+
272272 # Try to update .env file
273273 env_updated = self ._update_env_file (org_id )
274-
274+
275275 if env_updated :
276276 self .notify (f"✓ Set default organization: { org_name } (ID: { org_id } )" )
277277 self .notify ("✓ Updated .env file with CODEGEN_ORG_ID" )
278278 else :
279279 self .notify (f"✓ Set organization: { org_name } (ID: { org_id } )" )
280280 self .notify ("ℹ Add 'export CODEGEN_ORG_ID={org_id}' to your shell for persistence" )
281-
281+
282282 # Wait a moment for user to see the notifications, then exit
283283 self .set_timer (2.0 , self .exit )
284284
285285 def _update_env_file (self , org_id : int ) -> bool :
286286 """Update the .env file with the new organization ID."""
287287 env_file_path = ".env"
288-
288+
289289 try :
290290 lines = []
291291 key_found = False
@@ -314,9 +314,9 @@ def _update_env_file(self, org_id: int) -> bool:
314314 # Write back to file
315315 with open (env_file_path , "w" ) as f :
316316 f .writelines (lines )
317-
317+
318318 return True
319-
319+
320320 except Exception :
321321 return False
322322
0 commit comments