File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -197,13 +197,39 @@ def init_config():
197197
198198
199199@theme .command ()
200- def init ():
200+ @click .argument ('directory' , required = False )
201+ def init (directory ):
201202 """Initialize theme environment configuration."""
202- click .echo (click .style ('Initializing DevHub environment configuration...' , fg = 'green' ))
203+ original_working_dir = os .environ .get ('WORKING_DIR' , os .getcwd ())
204+
205+ if directory :
206+ # Check if directory already exists
207+ if os .path .exists (directory ):
208+ click .echo (click .style (f'Error: Directory "{ directory } " already exists' , fg = 'red' ))
209+ return
210+
211+ # Create the directory
212+ try :
213+ os .makedirs (directory , exist_ok = False )
214+ click .echo (click .style (f'Created directory: { directory } ' , fg = 'green' ))
215+ except OSError as e :
216+ click .echo (click .style (f'Error creating directory "{ directory } ": { e } ' , fg = 'red' ))
217+ return
218+
219+ # Update WORKING_DIR to the new directory
220+ absolute_directory = os .path .abspath (directory )
221+ os .environ ['WORKING_DIR' ] = absolute_directory
222+ click .echo (click .style (f'Initializing DevHub environment configuration in { absolute_directory } ...' , fg = 'green' ))
223+ else :
224+ click .echo (click .style ('Initializing DevHub environment configuration...' , fg = 'green' ))
203225
204- init_env ()
205- init_gitignore ()
206- init_config ()
226+ try :
227+ init_env ()
228+ init_gitignore ()
229+ init_config ()
230+ finally :
231+ # Restore original WORKING_DIR
232+ os .environ ['WORKING_DIR' ] = original_working_dir
207233
208234
209235@theme .command ()
You can’t perform that action at this time.
0 commit comments