@@ -782,6 +782,7 @@ mod tests {
782
782
values,
783
783
accept_defaults : false ,
784
784
no_vcs : false ,
785
+ allow_overwrite : false ,
785
786
} ;
786
787
787
788
template. run ( options) . silent ( ) . await . unwrap ( ) ;
@@ -816,6 +817,7 @@ mod tests {
816
817
values,
817
818
accept_defaults : true ,
818
819
no_vcs : false ,
820
+ allow_overwrite : false ,
819
821
} ;
820
822
821
823
template. run ( options) . silent ( ) . await . unwrap ( ) ;
@@ -882,6 +884,7 @@ mod tests {
882
884
values,
883
885
accept_defaults : false ,
884
886
no_vcs : false ,
887
+ allow_overwrite : false ,
885
888
} ;
886
889
887
890
template. run ( options) . silent ( ) . await . unwrap ( ) ;
@@ -910,6 +913,7 @@ mod tests {
910
913
values,
911
914
accept_defaults : false ,
912
915
no_vcs : false ,
916
+ allow_overwrite : false ,
913
917
} ;
914
918
915
919
template. run ( options) . silent ( ) . await . unwrap ( ) ;
@@ -935,6 +939,7 @@ mod tests {
935
939
values,
936
940
accept_defaults : false ,
937
941
no_vcs : false ,
942
+ allow_overwrite : false ,
938
943
} ;
939
944
940
945
template. run ( options) . silent ( ) . await . unwrap ( ) ;
@@ -992,6 +997,7 @@ mod tests {
992
997
values,
993
998
accept_defaults : false ,
994
999
no_vcs : false ,
1000
+ allow_overwrite : false ,
995
1001
} ;
996
1002
997
1003
template. run ( options) . silent ( ) . await . unwrap ( ) ;
@@ -1020,6 +1026,7 @@ mod tests {
1020
1026
values,
1021
1027
accept_defaults : false ,
1022
1028
no_vcs : false ,
1029
+ allow_overwrite : false ,
1023
1030
} ;
1024
1031
1025
1032
template. run ( options) . silent ( ) . await . unwrap ( ) ;
@@ -1072,6 +1079,7 @@ mod tests {
1072
1079
values,
1073
1080
accept_defaults : false ,
1074
1081
no_vcs : false ,
1082
+ allow_overwrite : false ,
1075
1083
} ;
1076
1084
1077
1085
template. run ( options) . silent ( ) . await . unwrap ( ) ;
@@ -1100,6 +1108,7 @@ mod tests {
1100
1108
values,
1101
1109
accept_defaults : false ,
1102
1110
no_vcs : false ,
1111
+ allow_overwrite : false ,
1103
1112
} ;
1104
1113
1105
1114
template. run ( options) . silent ( ) . await . unwrap ( ) ;
@@ -1125,6 +1134,7 @@ mod tests {
1125
1134
values,
1126
1135
accept_defaults : false ,
1127
1136
no_vcs : false ,
1137
+ allow_overwrite : false ,
1128
1138
} ;
1129
1139
1130
1140
template. run ( options) . silent ( ) . await . unwrap ( ) ;
@@ -1166,6 +1176,7 @@ mod tests {
1166
1176
values,
1167
1177
accept_defaults : false ,
1168
1178
no_vcs : true ,
1179
+ allow_overwrite : false ,
1169
1180
} ;
1170
1181
1171
1182
template. run ( options) . silent ( ) . await . unwrap ( ) ;
@@ -1205,6 +1216,7 @@ mod tests {
1205
1216
values,
1206
1217
accept_defaults : false ,
1207
1218
no_vcs : true ,
1219
+ allow_overwrite : false ,
1208
1220
} ;
1209
1221
1210
1222
template. run ( options) . silent ( ) . await . unwrap ( ) ;
@@ -1238,6 +1250,7 @@ mod tests {
1238
1250
values,
1239
1251
accept_defaults : false ,
1240
1252
no_vcs : true ,
1253
+ allow_overwrite : false ,
1241
1254
} ;
1242
1255
template. run ( options) . silent ( ) . await . unwrap ( ) ;
1243
1256
}
@@ -1288,6 +1301,7 @@ mod tests {
1288
1301
values,
1289
1302
accept_defaults : false ,
1290
1303
no_vcs : false ,
1304
+ allow_overwrite : false ,
1291
1305
} ;
1292
1306
1293
1307
template. run ( options) . silent ( ) . await . unwrap ( ) ;
@@ -1316,6 +1330,7 @@ mod tests {
1316
1330
values,
1317
1331
accept_defaults : false ,
1318
1332
no_vcs : false ,
1333
+ allow_overwrite : false ,
1319
1334
} ;
1320
1335
1321
1336
template. run ( options) . silent ( ) . await . unwrap ( ) ;
@@ -1377,6 +1392,7 @@ mod tests {
1377
1392
values,
1378
1393
accept_defaults : false ,
1379
1394
no_vcs : false ,
1395
+ allow_overwrite : false ,
1380
1396
} ;
1381
1397
1382
1398
template
@@ -1387,6 +1403,104 @@ mod tests {
1387
1403
}
1388
1404
}
1389
1405
1406
+ #[ tokio:: test]
1407
+ async fn cannot_generate_over_existing_files_by_default ( ) {
1408
+ let temp_dir = tempdir ( ) . unwrap ( ) ;
1409
+ let store = TemplateStore :: new ( temp_dir. path ( ) ) ;
1410
+ let manager = TemplateManager { store } ;
1411
+ let source = TemplateSource :: File ( project_root ( ) ) ;
1412
+
1413
+ manager
1414
+ . install ( & source, & InstallOptions :: default ( ) , & DiscardingReporter )
1415
+ . await
1416
+ . unwrap ( ) ;
1417
+
1418
+ let template = manager. get ( "http-rust" ) . unwrap ( ) . unwrap ( ) ;
1419
+
1420
+ let dest_temp_dir = tempdir ( ) . unwrap ( ) ;
1421
+ let output_dir = dest_temp_dir. path ( ) . join ( "myproj" ) ;
1422
+
1423
+ tokio:: fs:: create_dir_all ( & output_dir) . await . unwrap ( ) ;
1424
+ let manifest_path = output_dir. join ( "spin.toml" ) ;
1425
+ tokio:: fs:: write ( & manifest_path, "cookies" ) . await . unwrap ( ) ;
1426
+
1427
+ let values = [
1428
+ ( "project-description" . to_owned ( ) , "my desc" . to_owned ( ) ) ,
1429
+ ( "http-path" . to_owned ( ) , "/path/..." . to_owned ( ) ) ,
1430
+ ]
1431
+ . into_iter ( )
1432
+ . collect ( ) ;
1433
+ let options = RunOptions {
1434
+ variant : crate :: template:: TemplateVariantInfo :: NewApplication ,
1435
+ output_path : output_dir. clone ( ) ,
1436
+ name : "my project" . to_owned ( ) ,
1437
+ values,
1438
+ accept_defaults : false ,
1439
+ no_vcs : false ,
1440
+ allow_overwrite : false ,
1441
+ } ;
1442
+
1443
+ template
1444
+ . run ( options)
1445
+ . silent ( )
1446
+ . await
1447
+ . expect_err ( "generate into existing dir should have failed" ) ;
1448
+
1449
+ assert ! ( tokio:: fs:: read_to_string( & manifest_path)
1450
+ . await
1451
+ . unwrap( )
1452
+ . contains( "cookies" ) ) ;
1453
+ }
1454
+
1455
+ #[ tokio:: test]
1456
+ async fn can_generate_over_existing_files_if_so_configured ( ) {
1457
+ let temp_dir = tempdir ( ) . unwrap ( ) ;
1458
+ let store = TemplateStore :: new ( temp_dir. path ( ) ) ;
1459
+ let manager = TemplateManager { store } ;
1460
+ let source = TemplateSource :: File ( project_root ( ) ) ;
1461
+
1462
+ manager
1463
+ . install ( & source, & InstallOptions :: default ( ) , & DiscardingReporter )
1464
+ . await
1465
+ . unwrap ( ) ;
1466
+
1467
+ let template = manager. get ( "http-rust" ) . unwrap ( ) . unwrap ( ) ;
1468
+
1469
+ let dest_temp_dir = tempdir ( ) . unwrap ( ) ;
1470
+ let output_dir = dest_temp_dir. path ( ) . join ( "myproj" ) ;
1471
+
1472
+ tokio:: fs:: create_dir_all ( & output_dir) . await . unwrap ( ) ;
1473
+ let manifest_path = output_dir. join ( "spin.toml" ) ;
1474
+ tokio:: fs:: write ( & manifest_path, "cookies" ) . await . unwrap ( ) ;
1475
+
1476
+ let values = [
1477
+ ( "project-description" . to_owned ( ) , "my desc" . to_owned ( ) ) ,
1478
+ ( "http-path" . to_owned ( ) , "/path/..." . to_owned ( ) ) ,
1479
+ ]
1480
+ . into_iter ( )
1481
+ . collect ( ) ;
1482
+ let options = RunOptions {
1483
+ variant : crate :: template:: TemplateVariantInfo :: NewApplication ,
1484
+ output_path : output_dir. clone ( ) ,
1485
+ name : "my project" . to_owned ( ) ,
1486
+ values,
1487
+ accept_defaults : false ,
1488
+ no_vcs : false ,
1489
+ allow_overwrite : true ,
1490
+ } ;
1491
+
1492
+ template
1493
+ . run ( options)
1494
+ . silent ( )
1495
+ . await
1496
+ . expect ( "generate into existing dir should have succeeded" ) ;
1497
+
1498
+ assert ! ( tokio:: fs:: read_to_string( & manifest_path)
1499
+ . await
1500
+ . unwrap( )
1501
+ . contains( "[[trigger.http]]" ) ) ;
1502
+ }
1503
+
1390
1504
#[ tokio:: test]
1391
1505
async fn cannot_new_a_component_only_template ( ) {
1392
1506
let temp_dir = tempdir ( ) . unwrap ( ) ;
@@ -1447,6 +1561,7 @@ mod tests {
1447
1561
values,
1448
1562
accept_defaults : false ,
1449
1563
no_vcs : false ,
1564
+ allow_overwrite : false ,
1450
1565
} ;
1451
1566
1452
1567
let err = template
0 commit comments