@@ -317,6 +317,8 @@ def app_template_questions(
317
317
if mode == "express" and not express_available :
318
318
raise Exception ("Express mode not available for that template." )
319
319
320
+ dest_dir = directory_prompt (dest_dir , template_dir .name )
321
+
320
322
if mode is None and express_available :
321
323
mode = questionary .select (
322
324
"Would you like to use Shiny Express?" ,
@@ -334,8 +336,6 @@ def app_template_questions(
334
336
use_template_internal ()
335
337
return
336
338
337
- dest_dir = directory_prompt (template_dir , dest_dir )
338
-
339
339
app_dir = copy_template_files (
340
340
dest_dir ,
341
341
template_dir = template_dir ,
@@ -404,7 +404,7 @@ def js_component_questions(
404
404
Path (__file__ ).parent / "templates/package-templates" / component_type
405
405
)
406
406
407
- dest_dir = directory_prompt (template_dir , dest_dir )
407
+ dest_dir = directory_prompt (dest_dir , package_name )
408
408
409
409
app_dir = copy_template_files (
410
410
dest_dir ,
@@ -437,21 +437,32 @@ def js_component_questions(
437
437
438
438
439
439
def directory_prompt (
440
- template_dir : Path , dest_dir : Optional [Path | str | None ] = None
440
+ dest_dir : Optional [Path | str | None ] = None ,
441
+ default_dir : Optional [str | None ] = None ,
441
442
) -> Path :
442
443
if dest_dir is not None :
443
- return Path (dest_dir )
444
+ dest_dir = Path (dest_dir )
445
+
446
+ if dest_dir .exists () and dest_dir .is_file ():
447
+ click .echo (
448
+ cli_danger (
449
+ f"Error: Destination directory { cli_field (str (dest_dir ))} is a file, not a directory."
450
+ )
451
+ )
452
+ sys .exit (1 )
453
+ return dest_dir
444
454
445
455
app_dir = questionary .path (
446
456
"Enter destination directory:" ,
447
- default = path_rel_wd (template_dir . name ) ,
457
+ default = path_rel_wd (default_dir ) if default_dir is not None else "./" ,
448
458
only_directories = True ,
449
459
).ask ()
450
460
451
461
if app_dir is None :
452
462
sys .exit (1 )
453
463
454
- return Path (app_dir )
464
+ # Perform not-a-file check on the selected `app_dir`
465
+ return directory_prompt (dest_dir = app_dir )
455
466
456
467
457
468
def path_rel_wd (* path : str ):
0 commit comments