@@ -178,6 +178,8 @@ def uninstall_template(project: c.Project, query: c.BaseTemplate, remove_user: b
178178@click .argument ('path' , type = click .Path ())
179179@click .argument ('target' , default = c .Conductor ().default_target , type = click .Choice (['v5' , 'cortex' ]))
180180@click .argument ('version' , default = 'latest' )
181+ @click .option ('--download/--no-download' , 'download_ok' , default = True , show_default = True ,
182+ help = '(Dis)allow download and use of remote templates in new projects' )
181183@click .option ('--force-user' , 'force_user' , default = False , is_flag = True ,
182184 help = 'Replace all user files in a template' )
183185@click .option ('--force-system' , '-f' , 'force_system' , default = False , is_flag = True ,
@@ -207,23 +209,45 @@ def new_project(ctx: click.Context, path: str, target: str, version: str,
207209 '! Delete it first. Are you creating a project in an existing one?' , extra = {'sentry' : False })
208210 ctx .exit (- 1 )
209211 try :
210- _conductor = c .Conductor ()
211- if target is None :
212+ project = _create_project (ctx = ctx , path = path ,target = target , version = version ,
213+ force_user = force_user , force_system = force_system ,
214+ compile_after = compile_after , build_cache = build_cache , ** kwargs )
215+ ctx .exit (project .compile ([], scan_build = build_cache ))
216+ except Exception as e :
217+ try :
218+ kwargs ['allow_online' ] = False
219+ project = _create_project (ctx = ctx , path = path ,target = target , version = version ,
220+ force_user = force_user , force_system = force_system ,
221+ compile_after = compile_after , build_cache = build_cache , ** kwargs )
222+ logger (__name__ ).error ('Could not connect to GitHub. Check your internet connection or consult a network administrator.' ,
223+ extra = {'sentry' : False })
224+ ctx .exit (project .compile ([], scan_build = build_cache ))
225+ except Exception as _e :
226+ pros .common .logger (__name__ ).exception (e )
227+ ctx .exit (- 1 )
228+
229+
230+ def _create_project (ctx : click .Context , path : str , target : str , version : str ,
231+ force_user : bool = False , force_system : bool = False ,
232+ no_default_libs : bool = False , compile_after : bool = True , build_cache : bool = None , ** kwargs ):
233+ """
234+ Helper function for new_project
235+
236+ Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more
237+ """
238+ _conductor = c .Conductor ()
239+ if target is None :
212240 target = _conductor .default_target
213- project = _conductor .new_project (path , target = target , version = version ,
241+ project = _conductor .new_project (path , target = target , version = version ,
214242 force_user = force_user , force_system = force_system ,
215243 no_default_libs = no_default_libs , ** kwargs )
216- ui .echo ('New PROS Project was created:' , output_machine = False )
217- ctx .invoke (info_project , project = project )
218-
219- if compile_after or build_cache :
220- with ui .Notification ():
221- ui .echo ('Building project...' )
222- ctx .exit (project .compile ([], scan_build = build_cache ))
223-
224- except Exception as e :
225- pros .common .logger (__name__ ).exception (e )
226- ctx .exit (- 1 )
244+ ui .echo ('New PROS Project was created:' , output_machine = False )
245+ ctx .invoke (info_project , project = project )
246+ if compile_after or build_cache :
247+ with ui .Notification ():
248+ ui .echo ('Building project...' )
249+ return project
250+
227251
228252
229253@conductor .command ('query-templates' ,
0 commit comments