1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
|
//! Command-line parsing for the Composer CLI, built with bpaf combinators.
//!
//! TODO(phase-c): bpaf does not expand bundled short flags for subcommand-level
//! options. `disambiguate_short` only sees the top-level short flag set, so a
//! bundle like `-il` (= `-i -l`) declared inside a subcommand is not split:
//! `dump-autoload -oa` errors with "`-oa` is not expected", and for commands
//! with an optional positional (e.g. `show -il pkg`) the bundle is silently
//! absorbed as the positional, dropping the real argument. The separated form
//! (`-i -l`) and long form (`--installed --latest`) work correctly. Symfony
//! expands bundles, so this is a compatibility gap affecting every command.
//! Options to fix: pre-split bundles before handing args to bpaf, or drop
//! bpaf subcommands and dispatch each command as its own top-level parser via
//! `run_inner` (so each parser knows its own short flags at disambiguation).
use bpaf::{OptionParser, Parser, construct, long, positional, pure};
fn named(name: &'static str, short_c: Option<char>) -> bpaf::parsers::NamedArg {
match short_c {
Some(c) => long(name).short(c),
None => long(name),
}
}
/// VALUE_NONE option.
fn flag(name: &'static str, short_c: Option<char>, help: &'static str) -> impl Parser<bool> {
named(name, short_c).help(help).switch()
}
/// VALUE_REQUIRED option without a default.
fn value(
name: &'static str,
short_c: Option<char>,
help: &'static str,
) -> impl Parser<Option<String>> {
named(name, short_c)
.help(help)
.argument::<String>("VALUE")
.optional()
}
/// VALUE_REQUIRED option with a string default.
fn value_default(
name: &'static str,
short_c: Option<char>,
help: &'static str,
default: &'static str,
) -> impl Parser<String> {
named(name, short_c)
.help(help)
.argument::<String>("VALUE")
.fallback(default.to_string())
}
/// VALUE_REQUIRED | VALUE_IS_ARRAY option.
fn value_many(
name: &'static str,
short_c: Option<char>,
help: &'static str,
) -> impl Parser<Vec<String>> {
named(name, short_c)
.help(help)
.argument::<String>("VALUE")
.many()
}
/// REQUIRED positional argument.
fn pos_req(name: &'static str, help: &'static str) -> impl Parser<String> {
positional::<String>(name).help(help)
}
/// OPTIONAL positional argument.
fn pos_opt(name: &'static str, help: &'static str) -> impl Parser<Option<String>> {
positional::<String>(name).help(help).optional()
}
/// IS_ARRAY (optionally OPTIONAL) positional argument.
fn pos_many(name: &'static str, help: &'static str) -> impl Parser<Vec<String>> {
positional::<String>(name).help(help).many()
}
/// IS_ARRAY | REQUIRED positional argument.
fn pos_some(name: &'static str, help: &'static str) -> impl Parser<Vec<String>> {
positional::<String>(name)
.help(help)
.some("at least one value is required")
}
#[derive(Debug, Clone)]
pub struct GlobalOptions {
pub profile: bool,
pub no_plugins: bool,
pub no_scripts: bool,
pub working_dir: Option<String>,
pub no_cache: bool,
pub quiet: bool,
pub verbose: usize,
pub version: bool,
pub ansi: Option<bool>,
pub no_interaction: bool,
}
fn global_options() -> impl Parser<GlobalOptions> {
let profile = flag(
"profile",
None,
"Display timing and memory usage information",
);
let no_plugins = flag("no-plugins", None, "Whether to disable plugins.");
let no_scripts = flag(
"no-scripts",
None,
"Skips the execution of all scripts defined in composer.json file.",
);
let working_dir = value(
"working-dir",
Some('d'),
"If specified, use the given directory as working directory.",
);
let no_cache = flag("no-cache", None, "Prevent use of the cache");
let quiet = flag("quiet", Some('q'), "Do not output any message");
// Symfony declares verbosity as -v|-vv|-vvv; bpaf counts repeated -v occurrences.
let verbose = long("verbose")
.short('v')
.help("Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug")
.req_flag(())
.count();
let version = flag("version", Some('V'), "Display this application version");
let ansi = {
let yes = long("ansi")
.help("Force (or disable --no-ansi) ANSI output")
.req_flag(true);
let no = long("no-ansi").help("Disable ANSI output").req_flag(false);
construct!([yes, no]).optional()
};
let no_interaction = flag(
"no-interaction",
Some('n'),
"Do not ask any interactive question",
);
construct!(GlobalOptions {
profile,
no_plugins,
no_scripts,
working_dir,
no_cache,
quiet,
verbose,
version,
ansi,
no_interaction,
})
}
#[derive(Debug, Clone)]
pub enum Command {
About,
Archive(ArchiveArgs),
Audit(AuditArgs),
Bump(BumpArgs),
CheckPlatformReqs(CheckPlatformReqsArgs),
ClearCache,
Config(ConfigArgs),
CreateProject(CreateProjectArgs),
Depends(DependsArgs),
Diagnose,
DumpAutoload(DumpAutoloadArgs),
Exec(ExecArgs),
Fund(FundArgs),
Global(GlobalArgs),
Browse(BrowseArgs),
Init(InitArgs),
Install(InstallArgs),
Licenses(LicensesArgs),
Outdated(OutdatedArgs),
Prohibits(ProhibitsArgs),
Reinstall(ReinstallArgs),
Remove(RemoveArgs),
Repository(RepositoryArgs),
Require(RequireArgs),
RunScript(RunScriptArgs),
Search(SearchArgs),
SelfUpdate(SelfUpdateArgs),
Show(ShowArgs),
Status,
Suggests(SuggestsArgs),
Update(UpdateArgs),
Validate(ValidateArgs),
}
// about
fn about_opts() -> OptionParser<Command> {
pure(Command::About)
.to_options()
.descr("Shows a short information about Composer")
}
// archive
#[derive(Debug, Clone)]
pub struct ArchiveArgs {
pub format: Option<String>,
pub dir: Option<String>,
pub file: Option<String>,
pub ignore_filters: bool,
pub package: Option<String>,
pub version: Option<String>,
}
fn archive_opts() -> OptionParser<Command> {
let format = value(
"format",
Some('f'),
"Format of the resulting archive: tar, tar.gz, tar.bz2 or zip (default tar)",
);
let dir = value("dir", None, "Write the archive to this directory");
let file = value(
"file",
None,
"Write the archive with the given file name. Note that the format will be appended.",
);
let ignore_filters = flag("ignore-filters", None, "Ignore filters when saving package");
let package = pos_opt(
"package",
"The package to archive instead of the current project",
);
let version = pos_opt(
"version",
"A version constraint to find the package to archive",
);
construct!(ArchiveArgs {
format,
dir,
file,
ignore_filters,
package,
version,
})
.map(Command::Archive)
.to_options()
.descr("Creates an archive of this composer package")
}
// audit
#[derive(Debug, Clone)]
pub struct AuditArgs {
pub no_dev: bool,
pub format: String,
pub locked: bool,
pub abandoned: Option<String>,
pub ignore_severity: Vec<String>,
pub ignore_unreachable: bool,
}
fn audit_opts() -> OptionParser<Command> {
let no_dev = flag("no-dev", None, "Disables auditing of require-dev packages.");
let format = value_default(
"format",
Some('f'),
"Output format. Must be \"table\", \"plain\", \"json\", or \"summary\".",
"table",
);
let locked = flag(
"locked",
None,
"Audit based on the lock file instead of the installed packages.",
);
let abandoned = value(
"abandoned",
None,
"Behavior on abandoned packages. Must be \"ignore\", \"report\", or \"fail\".",
);
let ignore_severity = value_many(
"ignore-severity",
None,
"Ignore advisories of a certain severity level.",
);
let ignore_unreachable = flag(
"ignore-unreachable",
None,
"Ignore repositories that are unreachable or return a non-200 status code.",
);
construct!(AuditArgs {
no_dev,
format,
locked,
abandoned,
ignore_severity,
ignore_unreachable,
})
.map(Command::Audit)
.to_options()
.descr("Checks for security vulnerability advisories for installed packages")
}
// bump
#[derive(Debug, Clone)]
pub struct BumpArgs {
pub dev_only: bool,
pub no_dev_only: bool,
pub dry_run: bool,
pub packages: Vec<String>,
}
fn bump_opts() -> OptionParser<Command> {
let dev_only = flag(
"dev-only",
Some('D'),
"Only bump requirements in \"require-dev\".",
);
let no_dev_only = flag(
"no-dev-only",
Some('R'),
"Only bump requirements in \"require\".",
);
let dry_run = flag(
"dry-run",
None,
"Outputs the packages to bump, but will not execute anything.",
);
let packages = pos_many(
"packages",
"Optional package name(s) to restrict which packages are bumped.",
);
construct!(BumpArgs {
dev_only,
no_dev_only,
dry_run,
packages,
})
.map(Command::Bump)
.to_options()
.descr("Increases the lower limit of your composer.json requirements to the currently installed versions")
}
// check-platform-reqs
#[derive(Debug, Clone)]
pub struct CheckPlatformReqsArgs {
pub no_dev: bool,
pub lock: bool,
pub format: String,
}
fn check_platform_reqs_opts() -> OptionParser<Command> {
let no_dev = flag(
"no-dev",
None,
"Disables checking of require-dev packages requirements.",
);
let lock = flag(
"lock",
None,
"Checks requirements only from the lock file, not from installed packages.",
);
let format = value_default(
"format",
Some('f'),
"Format of the output: text or json",
"text",
);
construct!(CheckPlatformReqsArgs {
no_dev,
lock,
format,
})
.map(Command::CheckPlatformReqs)
.to_options()
.descr("Check that platform requirements are satisfied")
}
// clear-cache
fn clear_cache_opts() -> OptionParser<Command> {
pure(Command::ClearCache)
.to_options()
.descr("Clears composer's internal package cache")
}
// config
#[derive(Debug, Clone)]
pub struct ConfigArgs {
pub global: bool,
pub editor: bool,
pub auth: bool,
pub unset: bool,
pub list: bool,
pub file: Option<String>,
pub absolute: bool,
pub json: bool,
pub merge: bool,
pub append: bool,
pub source: bool,
pub setting_key: Option<String>,
pub setting_value: Vec<String>,
}
fn config_opts() -> OptionParser<Command> {
let global = flag(
"global",
Some('g'),
"Apply command to the global config file",
);
let editor = flag("editor", Some('e'), "Open editor");
let auth = flag(
"auth",
Some('a'),
"Affect auth config file (only used for --editor)",
);
let unset = flag("unset", None, "Unset the given setting-key");
let list = flag("list", Some('l'), "List configuration settings");
let file = value(
"file",
Some('f'),
"If you want to choose a different composer.json or config.json",
);
let absolute = flag(
"absolute",
None,
"Returns absolute paths when fetching *-dir config values instead of relative",
);
let json = flag(
"json",
Some('j'),
"JSON decode the setting value, to be used with extra.* keys",
);
let merge = flag(
"merge",
Some('m'),
"Merge the setting value with the current value, to be used with extra.* or audit.ignore[-abandoned] keys in combination with --json",
);
let append = flag(
"append",
None,
"When adding a repository, append it (lowest priority) to the existing ones instead of prepending it (highest priority)",
);
let source = flag(
"source",
None,
"Display where the config value is loaded from",
);
let setting_key = pos_opt("setting-key", "Setting key");
let setting_value = pos_many("setting-value", "Setting value");
construct!(ConfigArgs {
global,
editor,
auth,
unset,
list,
file,
absolute,
json,
merge,
append,
source,
setting_key,
setting_value,
})
.map(Command::Config)
.to_options()
.descr("Sets config options")
}
// create-project
#[derive(Debug, Clone)]
pub struct CreateProjectArgs {
pub stability: Option<String>,
pub prefer_source: bool,
pub prefer_dist: bool,
pub prefer_install: Option<String>,
pub repository: Vec<String>,
pub repository_url: Option<String>,
pub add_repository: bool,
pub dev: bool,
pub no_dev: bool,
pub no_custom_installers: bool,
pub no_scripts: bool,
pub no_progress: bool,
pub no_secure_http: bool,
pub keep_vcs: bool,
pub remove_vcs: bool,
pub no_install: bool,
pub no_audit: bool,
pub audit_format: String,
pub no_security_blocking: bool,
pub ignore_platform_req: Vec<String>,
pub ignore_platform_reqs: bool,
pub ask: bool,
pub package: Option<String>,
pub directory: Option<String>,
pub version: Option<String>,
}
fn create_project_opts() -> OptionParser<Command> {
let stability = value(
"stability",
Some('s'),
"Minimum-stability allowed (unless a version is specified).",
);
let prefer_source = flag(
"prefer-source",
None,
"Forces installation from package sources when possible, including VCS information.",
);
let prefer_dist = flag(
"prefer-dist",
None,
"Forces installation from package dist (default behavior).",
);
let prefer_install = value(
"prefer-install",
None,
"Forces installation from package dist|source|auto (auto chooses source for dev versions, dist for the rest).",
);
let repository = value_many(
"repository",
None,
"Add custom repositories to look the package up, either by URL or using JSON arrays",
);
let repository_url = value(
"repository-url",
None,
"DEPRECATED: Use --repository instead.",
);
let add_repository = flag(
"add-repository",
None,
"Add the custom repository in the composer.json. If a lock file is present it will be deleted and an update will be run instead of install.",
);
let dev = flag(
"dev",
None,
"Enables installation of require-dev packages (enabled by default, only present for BC).",
);
let no_dev = flag(
"no-dev",
None,
"Disables installation of require-dev packages.",
);
let no_custom_installers = flag(
"no-custom-installers",
None,
"DEPRECATED: Use no-plugins instead.",
);
let no_scripts = flag(
"no-scripts",
None,
"Whether to prevent execution of all defined scripts in the root package.",
);
let no_progress = flag("no-progress", None, "Do not output download progress.");
let no_secure_http = flag(
"no-secure-http",
None,
"Disable the secure-http config option temporarily while installing the root package. Use at your own risk. Using this flag is a bad idea.",
);
let keep_vcs = flag(
"keep-vcs",
None,
"Whether to prevent deleting the vcs folder.",
);
let remove_vcs = flag(
"remove-vcs",
None,
"Whether to force deletion of the vcs folder without prompting.",
);
let no_install = flag(
"no-install",
None,
"Whether to skip installation of the package dependencies.",
);
let no_audit = flag(
"no-audit",
None,
"Whether to skip auditing of the installed package dependencies (can also be set via the COMPOSER_NO_AUDIT=1 env var).",
);
let audit_format = value_default(
"audit-format",
None,
"Audit output format. Must be \"table\", \"plain\", \"json\" or \"summary\".",
"summary",
);
let no_security_blocking = flag(
"no-security-blocking",
None,
"Allows installing packages with security advisories or that are abandoned (can also be set via the COMPOSER_NO_SECURITY_BLOCKING=1 env var).",
);
let ignore_platform_req = value_many(
"ignore-platform-req",
None,
"Ignore a specific platform requirement (php & ext- packages).",
);
let ignore_platform_reqs = flag(
"ignore-platform-reqs",
None,
"Ignore all platform requirements (php & ext- packages).",
);
let ask = flag("ask", None, "Whether to ask for project directory.");
let package = pos_opt("package", "Package name to be installed");
let directory = pos_opt("directory", "Directory where the files should be created");
let version = pos_opt("version", "Version, will default to latest");
construct!(CreateProjectArgs {
stability,
prefer_source,
prefer_dist,
prefer_install,
repository,
repository_url,
add_repository,
dev,
no_dev,
no_custom_installers,
no_scripts,
no_progress,
no_secure_http,
keep_vcs,
remove_vcs,
no_install,
no_audit,
audit_format,
no_security_blocking,
ignore_platform_req,
ignore_platform_reqs,
ask,
package,
directory,
version,
})
.map(Command::CreateProject)
.to_options()
.descr("Creates new project from a package into given directory")
}
// depends (why)
#[derive(Debug, Clone)]
pub struct DependsArgs {
pub recursive: bool,
pub tree: bool,
pub locked: bool,
pub package: String,
}
fn depends_opts() -> OptionParser<Command> {
let recursive = flag(
"recursive",
Some('r'),
"Recursively resolves up to the root package",
);
let tree = flag("tree", Some('t'), "Prints the results as a nested tree");
let locked = flag(
"locked",
None,
"Read dependency information from composer.lock",
);
let package = pos_req("package", "Package to inspect");
construct!(DependsArgs {
recursive,
tree,
locked,
package,
})
.map(Command::Depends)
.to_options()
.descr("Shows which packages cause the given package to be installed")
}
// diagnose
fn diagnose_opts() -> OptionParser<Command> {
pure(Command::Diagnose)
.to_options()
.descr("Diagnoses the system to identify common errors")
}
// dump-autoload
#[derive(Debug, Clone)]
pub struct DumpAutoloadArgs {
pub optimize: bool,
pub classmap_authoritative: bool,
pub apcu: bool,
pub apcu_prefix: Option<String>,
pub dry_run: bool,
pub dev: bool,
pub no_dev: bool,
pub ignore_platform_req: Vec<String>,
pub ignore_platform_reqs: bool,
pub strict_psr: bool,
pub strict_ambiguous: bool,
}
fn dump_autoload_opts() -> OptionParser<Command> {
let optimize = flag(
"optimize",
Some('o'),
"Optimizes PSR0 and PSR4 packages to be loaded with classmaps too, good for production.",
);
let classmap_authoritative = flag(
"classmap-authoritative",
Some('a'),
"Autoload classes from the classmap only. Implicitly enables `--optimize`.",
);
let apcu = flag("apcu", None, "Use APCu to cache found/not-found classes.");
let apcu_prefix = value(
"apcu-prefix",
None,
"Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu",
);
let dry_run = flag(
"dry-run",
None,
"Outputs the operations but will not execute anything.",
);
let dev = flag(
"dev",
None,
"Enables autoload-dev rules. Composer will by default infer this automatically according to the last install or update --no-dev state.",
);
let no_dev = flag(
"no-dev",
None,
"Disables autoload-dev rules. Composer will by default infer this automatically according to the last install or update --no-dev state.",
);
let ignore_platform_req = value_many(
"ignore-platform-req",
None,
"Ignore a specific platform requirement (php & ext- packages).",
);
let ignore_platform_reqs = flag(
"ignore-platform-reqs",
None,
"Ignore all platform requirements (php & ext- packages).",
);
let strict_psr = flag(
"strict-psr",
None,
"Return a failed status code (1) if PSR-4 or PSR-0 mapping errors are present. Requires --optimize to work.",
);
let strict_ambiguous = flag(
"strict-ambiguous",
None,
"Return a failed status code (2) if the same class is found in multiple files. Requires --optimize to work.",
);
construct!(DumpAutoloadArgs {
optimize,
classmap_authoritative,
apcu,
apcu_prefix,
dry_run,
dev,
no_dev,
ignore_platform_req,
ignore_platform_reqs,
strict_psr,
strict_ambiguous,
})
.map(Command::DumpAutoload)
.to_options()
.descr("Dumps the autoloader")
}
// exec
#[derive(Debug, Clone)]
pub struct ExecArgs {
pub list: bool,
pub binary: Option<String>,
pub args: Vec<String>,
}
fn exec_opts() -> OptionParser<Command> {
let list = flag("list", Some('l'), "");
let binary = pos_opt("binary", "The binary to run, e.g. phpunit");
let args = pos_many(
"args",
"Arguments to pass to the binary. Use -- to separate from composer arguments",
);
construct!(ExecArgs { list, binary, args })
.map(Command::Exec)
.to_options()
.descr("Executes a vendored binary/script")
}
// fund
#[derive(Debug, Clone)]
pub struct FundArgs {
pub format: String,
}
fn fund_opts() -> OptionParser<Command> {
let format = value_default(
"format",
Some('f'),
"Format of the output: text or json",
"text",
);
construct!(FundArgs { format })
.map(Command::Fund)
.to_options()
.descr("Discover how to help fund the maintenance of your dependencies")
}
// global
#[derive(Debug, Clone)]
pub struct GlobalArgs {
pub command_name: String,
pub args: Vec<String>,
}
fn global_opts() -> OptionParser<Command> {
let command_name = pos_req("command-name", "");
let args = pos_many("args", "");
construct!(GlobalArgs { command_name, args })
.map(Command::Global)
.to_options()
.descr("Allows running commands in the global composer dir ($COMPOSER_HOME)")
}
// browse (home)
#[derive(Debug, Clone)]
pub struct BrowseArgs {
pub homepage: bool,
pub show: bool,
pub packages: Vec<String>,
}
fn browse_opts() -> OptionParser<Command> {
let homepage = flag(
"homepage",
Some('H'),
"Open the homepage instead of the repository URL.",
);
let show = flag(
"show",
Some('s'),
"Only show the homepage or repository URL.",
);
let packages = pos_many("packages", "Package(s) to browse to.");
construct!(BrowseArgs {
homepage,
show,
packages,
})
.map(Command::Browse)
.to_options()
.descr("Opens the package's repository URL or homepage in your browser")
}
// init
#[derive(Debug, Clone)]
pub struct InitArgs {
pub name: Option<String>,
pub description: Option<String>,
pub author: Option<String>,
pub r#type: Option<String>,
pub homepage: Option<String>,
pub require: Vec<String>,
pub require_dev: Vec<String>,
pub stability: Option<String>,
pub license: Option<String>,
pub repository: Vec<String>,
pub autoload: Option<String>,
}
fn init_opts() -> OptionParser<Command> {
let name = value("name", None, "Name of the package");
let description = value("description", None, "Description of package");
let author = value("author", None, "Author name of package");
let r#type = value(
"type",
None,
"Type of package (e.g. library, project, metapackage, composer-plugin)",
);
let homepage = value("homepage", None, "Homepage of package");
let require = value_many(
"require",
None,
"Package to require with a version constraint, e.g. foo/bar:1.0.0 or foo/bar=1.0.0 or \"foo/bar 1.0.0\"",
);
let require_dev = value_many(
"require-dev",
None,
"Package to require for development with a version constraint, e.g. foo/bar:1.0.0 or foo/bar=1.0.0 or \"foo/bar 1.0.0\"",
);
let stability = value(
"stability",
Some('s'),
"Minimum stability (empty or one of: stable, RC, beta, alpha, dev)",
);
let license = value("license", Some('l'), "License of package");
let repository = value_many(
"repository",
None,
"Add custom repositories, either by URL or using JSON arrays",
);
let autoload = value(
"autoload",
Some('a'),
"Add PSR-4 autoload mapping. Maps your package's namespace to the provided directory. (Expects a relative path, e.g. src/)",
);
construct!(InitArgs {
name,
description,
author,
r#type,
homepage,
require,
require_dev,
stability,
license,
repository,
autoload,
})
.map(Command::Init)
.to_options()
.descr("Creates a basic composer.json file in current directory")
}
// install (i)
#[derive(Debug, Clone)]
pub struct InstallArgs {
pub prefer_source: bool,
pub prefer_dist: bool,
pub prefer_install: Option<String>,
pub dry_run: bool,
pub download_only: bool,
pub dev: bool,
pub no_suggest: bool,
pub no_dev: bool,
pub no_security_blocking: bool,
pub no_autoloader: bool,
pub no_progress: bool,
pub no_install: bool,
pub audit: bool,
pub audit_format: String,
// TODO(phase-c): `verbose` is unified into the global verbosity option (see
// GlobalOptions). Kept commented out because dropping the command-local
// definition changes `--help` output and must be reconciled with Symfony's
// merged InputDefinition.
// pub verbose: bool,
pub optimize_autoloader: bool,
pub classmap_authoritative: bool,
pub apcu_autoloader: bool,
pub apcu_autoloader_prefix: Option<String>,
pub ignore_platform_req: Vec<String>,
pub ignore_platform_reqs: bool,
pub packages: Vec<String>,
}
fn install_opts() -> OptionParser<Command> {
let prefer_source = flag(
"prefer-source",
None,
"Forces installation from package sources when possible, including VCS information.",
);
let prefer_dist = flag(
"prefer-dist",
None,
"Forces installation from package dist (default behavior).",
);
let prefer_install = value(
"prefer-install",
None,
"Forces installation from package dist|source|auto (auto chooses source for dev versions, dist for the rest).",
);
let dry_run = flag(
"dry-run",
None,
"Outputs the operations but will not execute anything (implicitly enables --verbose).",
);
let download_only = flag(
"download-only",
None,
"Download only, do not install packages.",
);
let dev = flag(
"dev",
None,
"DEPRECATED: Enables installation of require-dev packages (enabled by default, only present for BC).",
);
let no_suggest = flag(
"no-suggest",
None,
"DEPRECATED: This flag does not exist anymore.",
);
let no_dev = flag(
"no-dev",
None,
"Disables installation of require-dev packages.",
);
let no_security_blocking = flag(
"no-security-blocking",
None,
"Allows installing packages with security advisories or that are abandoned (can also be set via the COMPOSER_NO_SECURITY_BLOCKING=1 env var). Only applies when no lock file is present.",
);
let no_autoloader = flag("no-autoloader", None, "Skips autoloader generation");
let no_progress = flag("no-progress", None, "Do not output download progress.");
let no_install = flag(
"no-install",
None,
"Do not use, only defined here to catch misuse of the install command.",
);
let audit = flag(
"audit",
None,
"Run an audit after installation is complete.",
);
let audit_format = value_default(
"audit-format",
None,
"Audit output format. Must be \"table\", \"plain\", \"json\", or \"summary\".",
"summary",
);
// TODO(phase-c): `verbose` (-v|-vv|-vvv) is unified into the global verbosity
// option; kept commented out because dropping it changes `--help` output and
// must be reconciled with Symfony's merged InputDefinition.
// let verbose = flag(
// "verbose",
// Some('v'),
// "Shows more details including new commits pulled in when updating packages.",
// );
let optimize_autoloader = flag(
"optimize-autoloader",
Some('o'),
"Optimize autoloader during autoloader dump",
);
let classmap_authoritative = flag(
"classmap-authoritative",
Some('a'),
"Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.",
);
let apcu_autoloader = flag(
"apcu-autoloader",
None,
"Use APCu to cache found/not-found classes.",
);
let apcu_autoloader_prefix = value(
"apcu-autoloader-prefix",
None,
"Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader",
);
let ignore_platform_req = value_many(
"ignore-platform-req",
None,
"Ignore a specific platform requirement (php & ext- packages).",
);
let ignore_platform_reqs = flag(
"ignore-platform-reqs",
None,
"Ignore all platform requirements (php & ext- packages).",
);
let packages = pos_many(
"packages",
"Should not be provided, use composer require instead to add a given package to composer.json.",
);
construct!(InstallArgs {
prefer_source,
prefer_dist,
prefer_install,
dry_run,
download_only,
dev,
no_suggest,
no_dev,
no_security_blocking,
no_autoloader,
no_progress,
no_install,
audit,
audit_format,
// verbose,
optimize_autoloader,
classmap_authoritative,
apcu_autoloader,
apcu_autoloader_prefix,
ignore_platform_req,
ignore_platform_reqs,
packages,
})
.map(Command::Install)
.to_options()
.descr("Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json")
}
// licenses
#[derive(Debug, Clone)]
pub struct LicensesArgs {
pub format: String,
pub no_dev: bool,
pub locked: bool,
}
fn licenses_opts() -> OptionParser<Command> {
let format = value_default(
"format",
Some('f'),
"Format of the output: text, json or summary",
"text",
);
let no_dev = flag("no-dev", None, "Disables search in require-dev packages.");
let locked = flag(
"locked",
None,
"Shows licenses from the lock file instead of installed packages.",
);
construct!(LicensesArgs {
format,
no_dev,
locked,
})
.map(Command::Licenses)
.to_options()
.descr("Shows information about licenses of dependencies")
}
// outdated
#[derive(Debug, Clone)]
pub struct OutdatedArgs {
pub outdated: bool,
pub all: bool,
pub locked: bool,
pub direct: bool,
pub strict: bool,
pub major_only: bool,
pub minor_only: bool,
pub patch_only: bool,
pub sort_by_age: bool,
pub format: String,
pub ignore: Vec<String>,
pub no_dev: bool,
pub ignore_platform_req: Vec<String>,
pub ignore_platform_reqs: bool,
pub package: Option<String>,
}
fn outdated_opts() -> OptionParser<Command> {
let outdated = flag(
"outdated",
Some('o'),
"Show only packages that are outdated (this is the default, but present here for compat with `show`",
);
let all = flag(
"all",
Some('a'),
"Show all installed packages with their latest versions",
);
let locked = flag(
"locked",
None,
"Shows updates for packages from the lock file, regardless of what is currently in vendor dir",
);
let direct = flag(
"direct",
Some('D'),
"Shows only packages that are directly required by the root package",
);
let strict = flag(
"strict",
None,
"Return a non-zero exit code when there are outdated packages",
);
let major_only = flag(
"major-only",
Some('M'),
"Show only packages that have major SemVer-compatible updates.",
);
let minor_only = flag(
"minor-only",
Some('m'),
"Show only packages that have minor SemVer-compatible updates.",
);
let patch_only = flag(
"patch-only",
Some('p'),
"Show only packages that have patch SemVer-compatible updates.",
);
let sort_by_age = flag(
"sort-by-age",
Some('A'),
"Displays the installed version's age, and sorts packages oldest first.",
);
let format = value_default(
"format",
Some('f'),
"Format of the output: text or json",
"text",
);
let ignore = value_many(
"ignore",
None,
"Ignore specified package(s). Can contain wildcards (*). Use it if you don't want to be informed about new versions of some packages.",
);
let no_dev = flag("no-dev", None, "Disables search in require-dev packages.");
let ignore_platform_req = value_many(
"ignore-platform-req",
None,
"Ignore a specific platform requirement (php & ext- packages). Use with the --outdated option",
);
let ignore_platform_reqs = flag(
"ignore-platform-reqs",
None,
"Ignore all platform requirements (php & ext- packages). Use with the --outdated option",
);
let package = pos_opt(
"package",
"Package to inspect. Or a name including a wildcard (*) to filter lists of packages instead.",
);
construct!(OutdatedArgs {
outdated,
all,
locked,
direct,
strict,
major_only,
minor_only,
patch_only,
sort_by_age,
format,
ignore,
no_dev,
ignore_platform_req,
ignore_platform_reqs,
package,
})
.map(Command::Outdated)
.to_options()
.descr("Shows a list of installed packages that have updates available, including their latest version")
}
// prohibits (why-not)
#[derive(Debug, Clone)]
pub struct ProhibitsArgs {
pub recursive: bool,
pub tree: bool,
pub locked: bool,
pub package: String,
pub version: String,
}
fn prohibits_opts() -> OptionParser<Command> {
let recursive = flag(
"recursive",
Some('r'),
"Recursively resolves up to the root package",
);
let tree = flag("tree", Some('t'), "Prints the results as a nested tree");
let locked = flag(
"locked",
None,
"Read dependency information from composer.lock",
);
let package = pos_req("package", "Package to inspect");
let version = pos_req(
"version",
"Version constraint, which version you expected to be installed",
);
construct!(ProhibitsArgs {
recursive,
tree,
locked,
package,
version,
})
.map(Command::Prohibits)
.to_options()
.descr("Shows which packages prevent the given package from being installed")
}
// reinstall
#[derive(Debug, Clone)]
pub struct ReinstallArgs {
pub prefer_source: bool,
pub prefer_dist: bool,
pub prefer_install: Option<String>,
pub no_autoloader: bool,
pub no_progress: bool,
pub optimize_autoloader: bool,
pub classmap_authoritative: bool,
pub apcu_autoloader: bool,
pub apcu_autoloader_prefix: Option<String>,
pub ignore_platform_req: Vec<String>,
pub ignore_platform_reqs: bool,
pub r#type: Vec<String>,
pub packages: Vec<String>,
}
fn reinstall_opts() -> OptionParser<Command> {
let prefer_source = flag(
"prefer-source",
None,
"Forces installation from package sources when possible, including VCS information.",
);
let prefer_dist = flag(
"prefer-dist",
None,
"Forces installation from package dist (default behavior).",
);
let prefer_install = value(
"prefer-install",
None,
"Forces installation from package dist|source|auto (auto chooses source for dev versions, dist for the rest).",
);
let no_autoloader = flag("no-autoloader", None, "Skips autoloader generation");
let no_progress = flag("no-progress", None, "Do not output download progress.");
let optimize_autoloader = flag(
"optimize-autoloader",
Some('o'),
"Optimize autoloader during autoloader dump",
);
let classmap_authoritative = flag(
"classmap-authoritative",
Some('a'),
"Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.",
);
let apcu_autoloader = flag(
"apcu-autoloader",
None,
"Use APCu to cache found/not-found classes.",
);
let apcu_autoloader_prefix = value(
"apcu-autoloader-prefix",
None,
"Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader",
);
let ignore_platform_req = value_many(
"ignore-platform-req",
None,
"Ignore a specific platform requirement (php & ext- packages).",
);
let ignore_platform_reqs = flag(
"ignore-platform-reqs",
None,
"Ignore all platform requirements (php & ext- packages).",
);
let r#type = value_many("type", None, "Filter packages to reinstall by type(s)");
let packages = pos_many(
"packages",
"List of package names to reinstall, can include a wildcard (*) to match any substring.",
);
construct!(ReinstallArgs {
prefer_source,
prefer_dist,
prefer_install,
no_autoloader,
no_progress,
optimize_autoloader,
classmap_authoritative,
apcu_autoloader,
apcu_autoloader_prefix,
ignore_platform_req,
ignore_platform_reqs,
r#type,
packages,
})
.map(Command::Reinstall)
.to_options()
.descr("Uninstalls and reinstalls the given package names")
}
// remove (rm, uninstall)
#[derive(Debug, Clone)]
pub struct RemoveArgs {
pub dev: bool,
pub dry_run: bool,
pub no_progress: bool,
pub no_update: bool,
pub no_install: bool,
pub no_audit: bool,
pub audit_format: String,
pub no_security_blocking: bool,
pub update_no_dev: bool,
pub update_with_dependencies: bool,
pub update_with_all_dependencies: bool,
pub with_all_dependencies: bool,
pub no_update_with_dependencies: bool,
pub minimal_changes: bool,
pub unused: bool,
pub ignore_platform_req: Vec<String>,
pub ignore_platform_reqs: bool,
pub optimize_autoloader: bool,
pub classmap_authoritative: bool,
pub apcu_autoloader: bool,
pub apcu_autoloader_prefix: Option<String>,
pub packages: Vec<String>,
}
fn remove_opts() -> OptionParser<Command> {
let dev = flag(
"dev",
None,
"Removes a package from the require-dev section.",
);
let dry_run = flag(
"dry-run",
None,
"Outputs the operations but will not execute anything (implicitly enables --verbose).",
);
let no_progress = flag("no-progress", None, "Do not output download progress.");
let no_update = flag(
"no-update",
None,
"Disables the automatic update of the dependencies (implies --no-install).",
);
let no_install = flag(
"no-install",
None,
"Skip the install step after updating the composer.lock file.",
);
let no_audit = flag(
"no-audit",
None,
"Skip the audit step after updating the composer.lock file (can also be set via the COMPOSER_NO_AUDIT=1 env var).",
);
let audit_format = value_default(
"audit-format",
None,
"Audit output format. Must be \"table\", \"plain\", \"json\", or \"summary\".",
"summary",
);
let no_security_blocking = flag(
"no-security-blocking",
None,
"Allows installing packages with security advisories or that are abandoned (can also be set via the COMPOSER_NO_SECURITY_BLOCKING=1 env var).",
);
let update_no_dev = flag(
"update-no-dev",
None,
"Run the dependency update with the --no-dev option.",
);
let update_with_dependencies = flag(
"update-with-dependencies",
Some('w'),
"Allows inherited dependencies to be updated with explicit dependencies (can also be set via the COMPOSER_WITH_DEPENDENCIES=1 env var). (Deprecated, is now default behavior)",
);
let update_with_all_dependencies = flag(
"update-with-all-dependencies",
Some('W'),
"Allows all inherited dependencies to be updated, including those that are root requirements (can also be set via the COMPOSER_WITH_ALL_DEPENDENCIES=1 env var).",
);
let with_all_dependencies = flag(
"with-all-dependencies",
None,
"Alias for --update-with-all-dependencies",
);
let no_update_with_dependencies = flag(
"no-update-with-dependencies",
None,
"Does not allow inherited dependencies to be updated with explicit dependencies.",
);
let minimal_changes = flag(
"minimal-changes",
Some('m'),
"During an update with -w/-W, only perform absolutely necessary changes to transitive dependencies (can also be set via the COMPOSER_MINIMAL_CHANGES=1 env var).",
);
let unused = flag(
"unused",
None,
"Remove all packages which are locked but not required by any other package.",
);
let ignore_platform_req = value_many(
"ignore-platform-req",
None,
"Ignore a specific platform requirement (php & ext- packages).",
);
let ignore_platform_reqs = flag(
"ignore-platform-reqs",
None,
"Ignore all platform requirements (php & ext- packages).",
);
let optimize_autoloader = flag(
"optimize-autoloader",
Some('o'),
"Optimize autoloader during autoloader dump",
);
let classmap_authoritative = flag(
"classmap-authoritative",
Some('a'),
"Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.",
);
let apcu_autoloader = flag(
"apcu-autoloader",
None,
"Use APCu to cache found/not-found classes.",
);
let apcu_autoloader_prefix = value(
"apcu-autoloader-prefix",
None,
"Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader",
);
let packages = pos_many("packages", "Packages that should be removed.");
construct!(RemoveArgs {
dev,
dry_run,
no_progress,
no_update,
no_install,
no_audit,
audit_format,
no_security_blocking,
update_no_dev,
update_with_dependencies,
update_with_all_dependencies,
with_all_dependencies,
no_update_with_dependencies,
minimal_changes,
unused,
ignore_platform_req,
ignore_platform_reqs,
optimize_autoloader,
classmap_authoritative,
apcu_autoloader,
apcu_autoloader_prefix,
packages,
})
.map(Command::Remove)
.to_options()
.descr("Removes a package from the require or require-dev")
}
// repository (repo)
#[derive(Debug, Clone)]
pub struct RepositoryArgs {
pub global: bool,
pub file: Option<String>,
pub append: bool,
pub before: Option<String>,
pub after: Option<String>,
pub action: String,
pub name: Option<String>,
pub arg1: Option<String>,
pub arg2: Option<String>,
}
fn repository_opts() -> OptionParser<Command> {
let global = flag(
"global",
Some('g'),
"Apply command to the global config file",
);
let file = value(
"file",
Some('f'),
"If you want to choose a different composer.json or config.json",
);
let append = flag(
"append",
None,
"When adding a repository, append it (lower priority) instead of prepending it",
);
let before = value(
"before",
None,
"When adding a repository, insert it before the given repository name",
);
let after = value(
"after",
None,
"When adding a repository, insert it after the given repository name",
);
let action = positional::<String>("action")
.help("Action to perform: list, add, remove, set-url, get-url, enable, disable")
.fallback("list".to_string());
let name = pos_opt(
"name",
"Repository name (or special name packagist.org for enable/disable)",
);
let arg1 = pos_opt(
"arg1",
"Type for add, or new URL for set-url, or JSON config for add",
);
let arg2 = pos_opt("arg2", "URL for add (if not using JSON)");
construct!(RepositoryArgs {
global,
file,
append,
before,
after,
action,
name,
arg1,
arg2,
})
.map(Command::Repository)
.to_options()
.descr("Manages repositories")
}
// require (r)
#[derive(Debug, Clone)]
pub struct RequireArgs {
pub dev: bool,
pub dry_run: bool,
pub prefer_source: bool,
pub prefer_dist: bool,
pub prefer_install: Option<String>,
pub fixed: bool,
pub no_suggest: bool,
pub no_progress: bool,
pub no_update: bool,
pub no_install: bool,
pub no_audit: bool,
pub audit_format: String,
pub no_security_blocking: bool,
pub update_no_dev: bool,
pub update_with_dependencies: bool,
pub update_with_all_dependencies: bool,
pub with_dependencies: bool,
pub with_all_dependencies: bool,
pub ignore_platform_req: Vec<String>,
pub ignore_platform_reqs: bool,
pub prefer_stable: bool,
pub prefer_lowest: bool,
pub minimal_changes: bool,
pub sort_packages: bool,
pub optimize_autoloader: bool,
pub classmap_authoritative: bool,
pub apcu_autoloader: bool,
pub apcu_autoloader_prefix: Option<String>,
pub packages: Vec<String>,
}
fn require_opts() -> OptionParser<Command> {
let dev = flag("dev", None, "Add requirement to require-dev.");
let dry_run = flag(
"dry-run",
None,
"Outputs the operations but will not execute anything (implicitly enables --verbose).",
);
let prefer_source = flag(
"prefer-source",
None,
"Forces installation from package sources when possible, including VCS information.",
);
let prefer_dist = flag(
"prefer-dist",
None,
"Forces installation from package dist (default behavior).",
);
let prefer_install = value(
"prefer-install",
None,
"Forces installation from package dist|source|auto (auto chooses source for dev versions, dist for the rest).",
);
let fixed = flag("fixed", None, "Write fixed version to the composer.json.");
let no_suggest = flag(
"no-suggest",
None,
"DEPRECATED: This flag does not exist anymore.",
);
let no_progress = flag("no-progress", None, "Do not output download progress.");
let no_update = flag(
"no-update",
None,
"Disables the automatic update of the dependencies (implies --no-install).",
);
let no_install = flag(
"no-install",
None,
"Skip the install step after updating the composer.lock file.",
);
let no_audit = flag(
"no-audit",
None,
"Skip the audit step after updating the composer.lock file (can also be set via the COMPOSER_NO_AUDIT=1 env var).",
);
let audit_format = value_default(
"audit-format",
None,
"Audit output format. Must be \"table\", \"plain\", \"json\", or \"summary\".",
"summary",
);
let no_security_blocking = flag(
"no-security-blocking",
None,
"Allows installing packages with security advisories or that are abandoned (can also be set via the COMPOSER_NO_SECURITY_BLOCKING=1 env var).",
);
let update_no_dev = flag(
"update-no-dev",
None,
"Run the dependency update with the --no-dev option.",
);
let update_with_dependencies = flag(
"update-with-dependencies",
Some('w'),
"Allows inherited dependencies to be updated, except those that are root requirements (can also be set via the COMPOSER_WITH_DEPENDENCIES=1 env var).",
);
let update_with_all_dependencies = flag(
"update-with-all-dependencies",
Some('W'),
"Allows all inherited dependencies to be updated, including those that are root requirements (can also be set via the COMPOSER_WITH_ALL_DEPENDENCIES=1 env var).",
);
let with_dependencies = flag(
"with-dependencies",
None,
"Alias for --update-with-dependencies",
);
let with_all_dependencies = flag(
"with-all-dependencies",
None,
"Alias for --update-with-all-dependencies",
);
let ignore_platform_req = value_many(
"ignore-platform-req",
None,
"Ignore a specific platform requirement (php & ext- packages).",
);
let ignore_platform_reqs = flag(
"ignore-platform-reqs",
None,
"Ignore all platform requirements (php & ext- packages).",
);
let prefer_stable = flag(
"prefer-stable",
None,
"Prefer stable versions of dependencies (can also be set via the COMPOSER_PREFER_STABLE=1 env var).",
);
let prefer_lowest = flag(
"prefer-lowest",
None,
"Prefer lowest versions of dependencies (can also be set via the COMPOSER_PREFER_LOWEST=1 env var).",
);
let minimal_changes = flag(
"minimal-changes",
Some('m'),
"During an update with -w/-W, only perform absolutely necessary changes to transitive dependencies (can also be set via the COMPOSER_MINIMAL_CHANGES=1 env var).",
);
let sort_packages = flag(
"sort-packages",
None,
"Sorts packages when adding/updating a new dependency",
);
let optimize_autoloader = flag(
"optimize-autoloader",
Some('o'),
"Optimize autoloader during autoloader dump",
);
let classmap_authoritative = flag(
"classmap-authoritative",
Some('a'),
"Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.",
);
let apcu_autoloader = flag(
"apcu-autoloader",
None,
"Use APCu to cache found/not-found classes.",
);
let apcu_autoloader_prefix = value(
"apcu-autoloader-prefix",
None,
"Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader",
);
let packages = pos_many(
"packages",
"Optional package name can also include a version constraint, e.g. foo/bar or foo/bar:1.0.0 or foo/bar=1.0.0 or \"foo/bar 1.0.0\"",
);
construct!(RequireArgs {
dev,
dry_run,
prefer_source,
prefer_dist,
prefer_install,
fixed,
no_suggest,
no_progress,
no_update,
no_install,
no_audit,
audit_format,
no_security_blocking,
update_no_dev,
update_with_dependencies,
update_with_all_dependencies,
with_dependencies,
with_all_dependencies,
ignore_platform_req,
ignore_platform_reqs,
prefer_stable,
prefer_lowest,
minimal_changes,
sort_packages,
optimize_autoloader,
classmap_authoritative,
apcu_autoloader,
apcu_autoloader_prefix,
packages,
})
.map(Command::Require)
.to_options()
.descr("Adds required packages to your composer.json and installs them")
}
// run-script (run)
#[derive(Debug, Clone)]
pub struct RunScriptArgs {
pub timeout: Option<String>,
pub dev: bool,
pub no_dev: bool,
pub list: bool,
pub script: Option<String>,
pub args: Vec<String>,
}
fn run_script_opts() -> OptionParser<Command> {
let timeout = value(
"timeout",
None,
"Sets script timeout in seconds, or 0 for never.",
);
let dev = flag("dev", None, "Sets the dev mode.");
let no_dev = flag("no-dev", None, "Disables the dev mode.");
let list = flag("list", Some('l'), "List scripts.");
let script = pos_opt("script", "Script name to run.");
let args = pos_many("args", "");
construct!(RunScriptArgs {
timeout,
dev,
no_dev,
list,
script,
args,
})
.map(Command::RunScript)
.to_options()
.descr("Runs the scripts defined in composer.json")
}
// search
#[derive(Debug, Clone)]
pub struct SearchArgs {
pub only_name: bool,
pub only_vendor: bool,
pub r#type: Option<String>,
pub format: String,
pub tokens: Vec<String>,
}
fn search_opts() -> OptionParser<Command> {
let only_name = flag("only-name", Some('N'), "Search only in package names");
let only_vendor = flag(
"only-vendor",
Some('O'),
"Search only for vendor / organization names, returns only \"vendor\" as result",
);
let r#type = value("type", Some('t'), "Search for a specific package type");
let format = value_default(
"format",
Some('f'),
"Format of the output: text or json",
"text",
);
let tokens = pos_some("tokens", "tokens to search for");
construct!(SearchArgs {
only_name,
only_vendor,
r#type,
format,
tokens,
})
.map(Command::Search)
.to_options()
.descr("Searches for packages")
}
// self-update (selfupdate)
#[derive(Debug, Clone)]
pub struct SelfUpdateArgs {
pub rollback: bool,
pub clean_backups: bool,
pub no_progress: bool,
pub update_keys: bool,
pub stable: bool,
pub preview: bool,
pub snapshot: bool,
pub v1: bool,
pub v2: bool,
pub v2_2: bool,
pub set_channel_only: bool,
pub version: Option<String>,
}
fn self_update_opts() -> OptionParser<Command> {
let rollback = flag(
"rollback",
Some('r'),
"Revert to an older installation of composer",
);
let clean_backups = flag(
"clean-backups",
None,
"Delete old backups during an update. This makes the current version of composer the only backup available after the update",
);
let no_progress = flag("no-progress", None, "Do not output download progress.");
let update_keys = flag("update-keys", None, "Prompt user for a key update");
let stable = flag("stable", None, "Force an update to the stable channel");
let preview = flag("preview", None, "Force an update to the preview channel");
let snapshot = flag("snapshot", None, "Force an update to the snapshot channel");
let v1 = flag(
"1",
None,
"Force an update to the stable channel, but only use 1.x versions",
);
let v2 = flag(
"2",
None,
"Force an update to the stable channel, but only use 2.x versions",
);
let v2_2 = flag(
"2.2",
None,
"Force an update to the stable channel, but only use 2.2.x LTS versions",
);
let set_channel_only = flag(
"set-channel-only",
None,
"Only store the channel as the default one and then exit",
);
let version = pos_opt("version", "The version to update to");
construct!(SelfUpdateArgs {
rollback,
clean_backups,
no_progress,
update_keys,
stable,
preview,
snapshot,
v1,
v2,
v2_2,
set_channel_only,
version,
})
.map(Command::SelfUpdate)
.to_options()
.descr("Updates composer.phar to the latest version")
}
// show (info)
#[derive(Debug, Clone)]
pub struct ShowArgs {
pub all: bool,
pub locked: bool,
pub installed: bool,
pub platform: bool,
pub available: bool,
pub self_: bool,
pub name_only: bool,
pub path: bool,
pub tree: bool,
pub latest: bool,
pub outdated: bool,
pub ignore: Vec<String>,
pub major_only: bool,
pub minor_only: bool,
pub patch_only: bool,
pub sort_by_age: bool,
pub direct: bool,
pub strict: bool,
pub format: String,
pub no_dev: bool,
pub ignore_platform_req: Vec<String>,
pub ignore_platform_reqs: bool,
pub package: Option<String>,
pub version: Option<String>,
}
fn show_opts() -> OptionParser<Command> {
let all = flag("all", None, "List all packages");
let locked = flag("locked", None, "List all locked packages");
let installed = flag(
"installed",
Some('i'),
"List installed packages only (enabled by default, only present for BC).",
);
let platform = flag("platform", Some('p'), "List platform packages only");
let available = flag("available", Some('a'), "List available packages only");
let self_ = flag("self", Some('s'), "Show the root package information");
let name_only = flag("name-only", Some('N'), "List package names only");
let path = flag("path", Some('P'), "Show package paths");
let tree = flag("tree", Some('t'), "List the dependencies as a tree");
let latest = flag("latest", Some('l'), "Show the latest version");
let outdated = flag(
"outdated",
Some('o'),
"Show the latest version but only for packages that are outdated",
);
let ignore = value_many(
"ignore",
None,
"Ignore specified package(s). Can contain wildcards (*). Use it with the --outdated option if you don't want to be informed about new versions of some packages.",
);
let major_only = flag(
"major-only",
Some('M'),
"Show only packages that have major SemVer-compatible updates. Use with the --latest or --outdated option.",
);
let minor_only = flag(
"minor-only",
Some('m'),
"Show only packages that have minor SemVer-compatible updates. Use with the --latest or --outdated option.",
);
let patch_only = flag(
"patch-only",
None,
"Show only packages that have patch SemVer-compatible updates. Use with the --latest or --outdated option.",
);
let sort_by_age = flag(
"sort-by-age",
Some('A'),
"Displays the installed version's age, and sorts packages oldest first. Use with the --latest or --outdated option.",
);
let direct = flag(
"direct",
Some('D'),
"Shows only packages that are directly required by the root package",
);
let strict = flag(
"strict",
None,
"Return a non-zero exit code when there are outdated packages",
);
let format = value_default(
"format",
Some('f'),
"Format of the output: text or json",
"text",
);
let no_dev = flag("no-dev", None, "Disables search in require-dev packages.");
let ignore_platform_req = value_many(
"ignore-platform-req",
None,
"Ignore a specific platform requirement (php & ext- packages). Use with the --outdated option",
);
let ignore_platform_reqs = flag(
"ignore-platform-reqs",
None,
"Ignore all platform requirements (php & ext- packages). Use with the --outdated option",
);
let package = pos_opt(
"package",
"Package to inspect. Or a name including a wildcard (*) to filter lists of packages instead.",
);
let version = pos_opt("version", "Version or version constraint to inspect");
construct!(ShowArgs {
all,
locked,
installed,
platform,
available,
self_,
name_only,
path,
tree,
latest,
outdated,
ignore,
major_only,
minor_only,
patch_only,
sort_by_age,
direct,
strict,
format,
no_dev,
ignore_platform_req,
ignore_platform_reqs,
package,
version,
})
.map(Command::Show)
.to_options()
.descr("Shows information about packages")
}
// status
// TODO(phase-c): `verbose` is unified into the global verbosity option (see
// GlobalOptions). Kept commented out because dropping the command-local
// definition changes `--help` output and must be reconciled with Symfony's
// merged InputDefinition. Once restored, `Command::Status` should carry a
// `StatusArgs` payload again.
// #[derive(Debug, Clone)]
// pub struct StatusArgs {
// pub verbose: bool,
// }
fn status_opts() -> OptionParser<Command> {
// let verbose = flag(
// "verbose",
// Some('v'),
// "Show modified files for each directory that contains changes.",
// );
pure(Command::Status)
.to_options()
.descr("Shows a list of locally modified packages")
}
// suggests
#[derive(Debug, Clone)]
pub struct SuggestsArgs {
pub by_package: bool,
pub by_suggestion: bool,
pub all: bool,
pub list: bool,
pub no_dev: bool,
pub packages: Vec<String>,
}
fn suggests_opts() -> OptionParser<Command> {
let by_package = flag(
"by-package",
None,
"Groups output by suggesting package (default)",
);
let by_suggestion = flag("by-suggestion", None, "Groups output by suggested package");
let all = flag(
"all",
Some('a'),
"Show suggestions from all dependencies, including transitive ones",
);
let list = flag("list", None, "Show only list of suggested package names");
let no_dev = flag(
"no-dev",
None,
"Exclude suggestions from require-dev packages",
);
let packages = pos_many(
"packages",
"Packages that you want to list suggestions from.",
);
construct!(SuggestsArgs {
by_package,
by_suggestion,
all,
list,
no_dev,
packages,
})
.map(Command::Suggests)
.to_options()
.descr("Shows package suggestions")
}
// update (u, upgrade)
/// VALUE_OPTIONAL representation for `--bump-after-update`: the flag may be
/// absent, present without a value, or present with a value (only the `=value`
/// form provides a value, matching Symfony's optional-value semantics).
#[derive(Debug, Clone)]
pub enum BumpAfterUpdate {
Absent,
Present,
Value(String),
}
#[derive(Debug, Clone)]
pub struct UpdateArgs {
pub with: Vec<String>,
pub prefer_source: bool,
pub prefer_dist: bool,
pub prefer_install: Option<String>,
pub dry_run: bool,
pub dev: bool,
pub no_dev: bool,
pub lock: bool,
pub no_install: bool,
pub no_audit: bool,
pub audit_format: String,
pub no_security_blocking: bool,
pub no_autoloader: bool,
pub no_suggest: bool,
pub no_progress: bool,
pub with_dependencies: bool,
pub with_all_dependencies: bool,
pub optimize_autoloader: bool,
pub classmap_authoritative: bool,
pub apcu_autoloader: bool,
pub apcu_autoloader_prefix: Option<String>,
pub ignore_platform_req: Vec<String>,
pub ignore_platform_reqs: bool,
pub prefer_stable: bool,
pub prefer_lowest: bool,
pub minimal_changes: bool,
pub patch_only: bool,
pub interactive: bool,
pub root_reqs: bool,
pub bump_after_update: BumpAfterUpdate,
pub packages: Vec<String>,
}
fn update_opts() -> OptionParser<Command> {
let with = value_many(
"with",
None,
"Temporary version constraint to add, e.g. foo/bar:1.0.0 or foo/bar=1.0.0",
);
let prefer_source = flag(
"prefer-source",
None,
"Forces installation from package sources when possible, including VCS information.",
);
let prefer_dist = flag(
"prefer-dist",
None,
"Forces installation from package dist (default behavior).",
);
let prefer_install = value(
"prefer-install",
None,
"Forces installation from package dist|source|auto (auto chooses source for dev versions, dist for the rest).",
);
let dry_run = flag(
"dry-run",
None,
"Outputs the operations but will not execute anything (implicitly enables --verbose).",
);
let dev = flag(
"dev",
None,
"DEPRECATED: Enables installation of require-dev packages (enabled by default, only present for BC).",
);
let no_dev = flag(
"no-dev",
None,
"Disables installation of require-dev packages.",
);
let lock = flag(
"lock",
None,
"Overwrites the lock file hash to suppress warning about the lock file being out of date without updating package versions. Package metadata like mirrors and URLs are updated if they changed.",
);
let no_install = flag(
"no-install",
None,
"Skip the install step after updating the composer.lock file.",
);
let no_audit = flag(
"no-audit",
None,
"Skip the audit step after updating the composer.lock file (can also be set via the COMPOSER_NO_AUDIT=1 env var).",
);
let audit_format = value_default(
"audit-format",
None,
"Audit output format. Must be \"table\", \"plain\", \"json\", or \"summary\".",
"summary",
);
let no_security_blocking = flag(
"no-security-blocking",
None,
"Allows installing packages with security advisories or that are abandoned (can also be set via the COMPOSER_NO_SECURITY_BLOCKING=1 env var).",
);
let no_autoloader = flag("no-autoloader", None, "Skips autoloader generation");
let no_suggest = flag(
"no-suggest",
None,
"DEPRECATED: This flag does not exist anymore.",
);
let no_progress = flag("no-progress", None, "Do not output download progress.");
let with_dependencies = flag(
"with-dependencies",
Some('w'),
"Update also dependencies of packages in the argument list, except those which are root requirements (can also be set via the COMPOSER_WITH_DEPENDENCIES=1 env var).",
);
let with_all_dependencies = flag(
"with-all-dependencies",
Some('W'),
"Update also dependencies of packages in the argument list, including those which are root requirements (can also be set via the COMPOSER_WITH_ALL_DEPENDENCIES=1 env var).",
);
// TODO(phase-c): `verbose` (-v|-vv|-vvv) is unified into the global verbosity
// option; kept commented out because dropping it changes `--help` output and
// must be reconciled with Symfony's merged InputDefinition.
// let verbose = flag(
// "verbose",
// Some('v'),
// "Shows more details including new commits pulled in when updating packages.",
// );
let optimize_autoloader = flag(
"optimize-autoloader",
Some('o'),
"Optimize autoloader during autoloader dump.",
);
let classmap_authoritative = flag(
"classmap-authoritative",
Some('a'),
"Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.",
);
let apcu_autoloader = flag(
"apcu-autoloader",
None,
"Use APCu to cache found/not-found classes.",
);
let apcu_autoloader_prefix = value(
"apcu-autoloader-prefix",
None,
"Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader",
);
let ignore_platform_req = value_many(
"ignore-platform-req",
None,
"Ignore a specific platform requirement (php & ext- packages).",
);
let ignore_platform_reqs = flag(
"ignore-platform-reqs",
None,
"Ignore all platform requirements (php & ext- packages).",
);
let prefer_stable = flag(
"prefer-stable",
None,
"Prefer stable versions of dependencies (can also be set via the COMPOSER_PREFER_STABLE=1 env var).",
);
let prefer_lowest = flag(
"prefer-lowest",
None,
"Prefer lowest versions of dependencies (can also be set via the COMPOSER_PREFER_LOWEST=1 env var).",
);
let minimal_changes = flag(
"minimal-changes",
Some('m'),
"Only perform absolutely necessary changes to dependencies. If packages cannot be kept at their currently locked version they are updated. For partial updates the allow-listed packages are always updated fully. (can also be set via the COMPOSER_MINIMAL_CHANGES=1 env var).",
);
let patch_only = flag(
"patch-only",
None,
"Only allow patch version updates for currently installed dependencies.",
);
let interactive = flag(
"interactive",
Some('i'),
"Interactive interface with autocompletion to select the packages to update.",
);
let root_reqs = flag(
"root-reqs",
None,
"Restricts the update to your first degree dependencies.",
);
// VALUE_OPTIONAL with default `false`: only the `--bump-after-update=value`
// form supplies a value; the bare flag means "present without value".
let bump_after_update = {
let with_value = long("bump-after-update")
.help("Runs bump after performing the update.")
.argument::<String>("MODE")
.adjacent()
.map(BumpAfterUpdate::Value);
let bare = long("bump-after-update").req_flag(BumpAfterUpdate::Present);
construct!([with_value, bare]).fallback(BumpAfterUpdate::Absent)
};
let packages = pos_many(
"packages",
"Packages that should be updated, if not provided all packages are.",
);
construct!(UpdateArgs {
with,
prefer_source,
prefer_dist,
prefer_install,
dry_run,
dev,
no_dev,
lock,
no_install,
no_audit,
audit_format,
no_security_blocking,
no_autoloader,
no_suggest,
no_progress,
with_dependencies,
with_all_dependencies,
optimize_autoloader,
classmap_authoritative,
apcu_autoloader,
apcu_autoloader_prefix,
ignore_platform_req,
ignore_platform_reqs,
prefer_stable,
prefer_lowest,
minimal_changes,
patch_only,
interactive,
root_reqs,
bump_after_update,
packages,
})
.map(Command::Update)
.to_options()
.descr("Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file")
}
// validate
#[derive(Debug, Clone)]
pub struct ValidateArgs {
pub no_check_all: bool,
pub check_lock: bool,
pub no_check_lock: bool,
pub no_check_publish: bool,
pub no_check_version: bool,
pub with_dependencies: bool,
pub strict: bool,
pub file: Option<String>,
}
fn validate_opts() -> OptionParser<Command> {
let no_check_all = flag(
"no-check-all",
None,
"Do not validate requires for overly strict/loose constraints",
);
let check_lock = flag(
"check-lock",
None,
"Check if lock file is up to date (even when config.lock is false)",
);
let no_check_lock = flag(
"no-check-lock",
None,
"Do not check if lock file is up to date",
);
let no_check_publish = flag("no-check-publish", None, "Do not check for publish errors");
let no_check_version = flag(
"no-check-version",
None,
"Do not report a warning if the version field is present",
);
let with_dependencies = flag(
"with-dependencies",
Some('A'),
"Also validate the composer.json of all installed dependencies",
);
let strict = flag(
"strict",
None,
"Return a non-zero exit code for warnings as well as errors",
);
let file = pos_opt("file", "path to composer.json file");
construct!(ValidateArgs {
no_check_all,
check_lock,
no_check_lock,
no_check_publish,
no_check_version,
with_dependencies,
strict,
file,
})
.map(Command::Validate)
.to_options()
.descr("Validates a composer.json and composer.lock")
}
// TODO(phase-c): ScriptAliasCommand is constructed dynamically from composer.json
// `scripts`; it cannot be a static subcommand and must be registered at runtime
// once composer.json is loaded.
fn sub(
name: &'static str,
aliases: &[&'static str],
make: fn() -> OptionParser<Command>,
) -> Box<dyn Parser<Command>> {
let mut acc: Box<dyn Parser<Command>> = bpaf::command(name, make()).boxed();
for a in aliases {
acc = acc.or_else(bpaf::command(*a, make())).boxed();
}
acc
}
fn commands() -> Box<dyn Parser<Command>> {
let mut subs: Vec<Box<dyn Parser<Command>>> = vec![
sub("about", &[], about_opts),
sub("archive", &[], archive_opts),
sub("audit", &[], audit_opts),
sub("bump", &[], bump_opts),
sub("check-platform-reqs", &[], check_platform_reqs_opts),
sub("clear-cache", &["clearcache", "cc"], clear_cache_opts),
sub("config", &[], config_opts),
sub("create-project", &[], create_project_opts),
sub("depends", &["why"], depends_opts),
sub("diagnose", &[], diagnose_opts),
sub("dump-autoload", &["dumpautoload"], dump_autoload_opts),
sub("exec", &[], exec_opts),
sub("fund", &[], fund_opts),
sub("global", &[], global_opts),
sub("browse", &["home"], browse_opts),
sub("init", &[], init_opts),
sub("install", &["i"], install_opts),
sub("licenses", &[], licenses_opts),
sub("outdated", &[], outdated_opts),
sub("prohibits", &["why-not"], prohibits_opts),
sub("reinstall", &[], reinstall_opts),
sub("remove", &["rm", "uninstall"], remove_opts),
sub("repository", &["repo"], repository_opts),
sub("require", &["r"], require_opts),
sub("run-script", &["run"], run_script_opts),
sub("search", &[], search_opts),
sub("self-update", &["selfupdate"], self_update_opts),
sub("show", &["info"], show_opts),
sub("status", &[], status_opts),
sub("suggests", &[], suggests_opts),
sub("update", &["u", "upgrade"], update_opts),
sub("validate", &[], validate_opts),
];
let mut acc = subs.remove(0);
for s in subs {
acc = acc.or_else(s).boxed();
}
acc
}
#[derive(Debug, Clone)]
pub struct Cli {
pub global: GlobalOptions,
pub command: Command,
}
pub fn cli() -> OptionParser<Cli> {
let global = global_options();
let command = commands();
construct!(Cli { global, command })
.to_options()
.descr("Composer (Shirabe)")
}
|