~matthiasbeyer/butido

ref: 1a6511b138c86dd1304555d9b1ddccf716aa7ce1 butido/src/cli.rs -rw-r--r-- 56.0 KiB
1a6511b1Matthias Beyer Merge branch 'source-download-timeout' into next 1 year, 17 days ago
                                                                                
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
//
// Copyright (c) 2020-2021 science+computing ag and other contributors
//
// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/
//
// SPDX-License-Identifier: EPL-2.0
//

use std::path::PathBuf;
use std::str::FromStr;

use clap::crate_authors;
use clap::crate_version;
use clap::App;
use clap::Arg;
use clap::ArgGroup;

// Helper types to ship around stringly typed clap API.
pub const IDENT_DEPENDENCY_TYPE_BUILD: &str = "build";
pub const IDENT_DEPENDENCY_TYPE_RUNTIME: &str = "runtime";

pub fn cli<'a>() -> App<'a> {
    App::new("butido")
        .author(crate_authors!())
        .version(crate_version!())
        .about("Generic Build Orchestration System for building linux packages with docker")

        .after_help(indoc::indoc!(r#"
            The following environment variables can be passed to butido:

                RUST_LOG - to enable logging, for exact usage see the rust cookbook
        "#))

        .arg(Arg::new("hide_bars")
            .required(false)
            .multiple(false)
            .long("hide-bars")
            .about("Hide all progress bars")
        )

        .arg(Arg::new("database_host")
            .required(false)
            .multiple(false)
            .long("db-url")
            .value_name("HOST")
            .about("Override the database host")
            .long_about(indoc::indoc!(r#"
                Override the database host set via configuration.
                Can also be overriden via environment variable 'BUTIDO_DATABASE_HOST', but this setting has precedence.
            "#))
        )
        .arg(Arg::new("database_port")
            .required(false)
            .multiple(false)
            .long("db-port")
            .value_name("PORT")
            .about("Override the database port")
            .long_about(indoc::indoc!(r#"
                Override the database port set via configuration.
                Can also be overriden via environment 'BUTIDO_DATABASE_PORT', but this setting has precedence.
            "#))
        )
        .arg(Arg::new("database_user")
            .required(false)
            .multiple(false)
            .long("db-user")
            .value_name("USER")
            .about("Override the database user")
            .long_about(indoc::indoc!(r#"
                Override the database user set via configuration.
                Can also be overriden via environment 'BUTIDO_DATABASE_USER', but this setting has precedence.
            "#))
        )
        .arg(Arg::new("database_password")
            .required(false)
            .multiple(false)
            .long("db-password")
            .alias("db-pw")
            .value_name("PASSWORD")
            .about("Override the database password")
            .long_about(indoc::indoc!(r#"
                Override the database password set via configuration.
                Can also be overriden via environment 'BUTIDO_DATABASE_PASSWORD', but this setting has precedence.
            "#))
        )
        .arg(Arg::new("database_name")
            .required(false)
            .multiple(false)
            .long("db-name")
            .value_name("NAME")
            .about("Override the database name")
            .long_about(indoc::indoc!(r#"
                Override the database name set via configuration.
                Can also be overriden via environment 'BUTIDO_DATABASE_NAME', but this setting has precedence.
            "#))
        )
        .arg(Arg::new("database_connection_timeout")
            .required(false)
            .multiple(false)
            .long("db-timeout")
            .value_name("TIMEOUT")
            .about("Override the database connection timeout")
            .long_about(indoc::indoc!(r#"
                Override the database connection timeout set via configuration.
                Can also be overriden via environment 'BUTIDO_DATABASE_CONNECTION_TIMEOUT', but this setting has precedence.
            "#))
        )

        .subcommand(App::new("generate-completions")
            .version(crate_version!())
            .about("Generate and print commandline completions")
            .arg(Arg::new("shell")
                .possible_values(&["bash", "elvish", "fish", "zsh"])
                .default_value("bash")
                .required(true)
                .multiple(false)
                .about("Shell to generate completions for")
            )
        )

        .subcommand(App::new("db")
            .version(crate_version!())
            .about("Database CLI interface")
            .subcommand(App::new("cli")
                .version(crate_version!())
                .about("Start a database CLI, if installed on the current host")
                .long_about(indoc::indoc!(r#"
                    Starts a database shell on the configured database using one of the following programs:

                        - psql
                        - pgcli

                    if installed.
                "#))

                .arg(Arg::new("tool")
                    .required(false)
                    .multiple(false)
                    .long("tool")
                    .value_name("TOOL")
                    .possible_values(&["psql", "pgcli"])
                    .about("Use a specific tool")
                )
            )

            .subcommand(App::new("setup")
                .version(crate_version!())
                .about("Run the database setup")
                .long_about(indoc::indoc!(r#"
                    Run the database setup migrations
                "#))
            )

            .subcommand(App::new("artifacts")
                .version(crate_version!())
                .about("List artifacts from the DB")
                .arg(Arg::new("csv")
                    .required(false)
                    .multiple(false)
                    .long("csv")
                    .takes_value(false)
                    .about("Format output as CSV")
                )
                .arg(Arg::new("job_uuid")
                    .required(false)
                    .multiple(false)
                    .long("job")
                    .short('J')
                    .takes_value(true)
                    .value_name("JOB UUID")
                    .about("Print only artifacts for a certain job")
                )
            )

            .subcommand(App::new("envvars")
                .version(crate_version!())
                .about("List envvars from the DB")
                .arg(Arg::new("csv")
                    .required(false)
                    .multiple(false)
                    .long("csv")
                    .takes_value(false)
                    .about("Format output as CSV")
                )
            )

            .subcommand(App::new("images")
                .version(crate_version!())
                .about("List images from the DB")
                .arg(Arg::new("csv")
                    .required(false)
                    .multiple(false)
                    .long("csv")
                    .takes_value(false)
                    .about("Format output as CSV")
                )
            )

            .subcommand(App::new("submit")
                .version(crate_version!())
                .about("Show details about one specific submit")
                .arg(Arg::new("submit")
                    .required(true)
                    .multiple(false)
                    .index(1)
                    .takes_value(true)
                    .value_name("SUBMIT")
                    .about("The Submit to show details about")
                )
            )

            .subcommand(App::new("submits")
                .version(crate_version!())
                .about("List submits from the DB")
                .arg(Arg::new("csv")
                    .required(false)
                    .multiple(false)
                    .long("csv")
                    .takes_value(false)
                    .about("Format output as CSV")
                )
                .arg(Arg::new("with_pkg")
                    .required(false)
                    .multiple(false)
                    .long("with-pkg")
                    .takes_value(true)
                    .value_name("PKG")
                    .about("Only list submits that contained package PKG")
                    .conflicts_with("for_pkg")
                )
                .arg(Arg::new("for_pkg")
                    .required(false)
                    .multiple(false)
                    .long("for-pkg")
                    .takes_value(true)
                    .value_name("PKG")
                    .about("Only list submits that had the root package PKG")
                    .conflicts_with("with_pkg")
                )
                .arg(Arg::new("limit")
                    .required(false)
                    .multiple(false)
                    .long("limit")
                    .takes_value(true)
                    .value_name("LIMIT")
                    .about("Only list LIMIT submits")
                )
                .arg(Arg::new("for-commit")
                    .required(false)
                    .multiple(false)
                    .long("commit")
                    .takes_value(true)
                    .value_name("HASH")
                    .about("Limit listed submits to one commit hash")
                )
                .arg(Arg::new("image")
                    .required(false)
                    .multiple(false)
                    .long("image")
                    .takes_value(true)
                    .value_name("IMAGE")
                    .about("Limit listed submits to submits on IMAGE")
                )
            )

            .subcommand(App::new("jobs")
                .version(crate_version!())
                .about("List jobs from the DB")
                .arg(Arg::new("csv")
                    .required(false)
                    .multiple(false)
                    .long("csv")
                    .takes_value(false)
                    .about("Format output as CSV")
                )

                .arg(Arg::new("submit_uuid")
                    .required(false)
                    .multiple(false)
                    .long("of-submit")
                    .short('S')
                    .takes_value(true)
                    .value_name("UUID")
                    .about("Only list jobs of a certain submit")
                )

                .arg(Arg::new("env_filter")
                    .required(false)
                    .multiple(false)
                    .long("env")
                    .short('E')
                    .takes_value(true)
                    .value_name("KV")
                    .about("Filter for this \"key=value\" environment variable")
                )

                .arg(Arg::new("limit")
                    .required(false)
                    .multiple(false)
                    .long("limit")
                    .short('L')
                    .takes_value(true)
                    .value_name("LIMIT")
                    .about("Only list newest LIMIT jobs instead of all")
                )

                .arg(arg_older_than_date("List only jobs older than DATE"))
                .arg(arg_newer_than_date("List only jobs newer than DATE"))

                .arg(Arg::new("endpoint")
                    .required(false)
                    .multiple(false)
                    .long("endpoint")
                    .short('e')
                    .takes_value(true)
                    .value_name("ENDPOINT")
                    .about("Only show jobs from ENDPOINT")
                )

                .arg(Arg::new("package")
                    .required(false)
                    .multiple(false)
                    .long("package")
                    .short('p')
                    .takes_value(true)
                    .value_name("PKG")
                    .about("Only show jobs for PKG")
                )

            )

            .subcommand(App::new("job")
                .version(crate_version!())
                .about("Show a specific job from the DB")
                .arg(Arg::new("csv")
                    .required(false)
                    .multiple(false)
                    .long("csv")
                    .takes_value(false)
                    .about("Format output as CSV")
                )

                .arg(Arg::new("job_uuid")
                    .required(true)
                    .multiple(false)
                    .index(1)
                    .takes_value(true)
                    .value_name("UUID")
                    .about("The job to show")
                )

                .arg(Arg::new("show_log")
                    .required(false)
                    .multiple(false)
                    .long("log")
                    .short('L')
                    .about("Show the log")
                )

                .arg(Arg::new("show_script")
                    .required(false)
                    .multiple(false)
                    .long("script")
                    .short('s')
                    .about("Show the script")
                )

                .arg(Arg::new("show_env")
                    .required(false)
                    .multiple(false)
                    .long("env")
                    .short('E')
                    .about("Show the environment of the job")
                )

                .arg(script_arg_line_numbers())
                .arg(script_arg_no_line_numbers())
                .arg(script_arg_highlight())
                .arg(script_arg_no_highlight())
            )
            .subcommand(App::new("log-of")
                .version(crate_version!())
                .about("Print log of a job, short version of 'db job --log'")
                .arg(Arg::new("job_uuid")
                    .required(true)
                    .multiple(false)
                    .index(1)
                    .takes_value(true)
                    .value_name("UUID")
                    .about("The id of the Job")
                )
            )
            .subcommand(App::new("releases")
                .version(crate_version!())
                .about("List releases")
                .arg(Arg::new("csv")
                    .required(false)
                    .multiple(false)
                    .long("csv")
                    .takes_value(false)
                    .about("Format output as CSV")
                )

                .arg(arg_older_than_date("List only releases older than DATE"))
                .arg(arg_newer_than_date("List only releases newer than DATE"))

                .arg(Arg::new("store")
                    .required(false)
                    .multiple(false)
                    .long("to")
                    .takes_value(true)
                    .value_name("STORE")
                    .about("List only releases to STORE")
                )

                .arg(Arg::new("package")
                    .required(false)
                    .multiple(false)
                    .long("package")
                    .short('p')
                    .takes_value(true)
                    .value_name("PKG")
                    .about("Only list releases for package PKG")
                )
            )
        )

        .subcommand(App::new("build")
            .version(crate_version!())
            .about("Build packages in containers")

            .arg(Arg::new("package_name")
                .required(true)
                .multiple(false)
                .index(1)
                .value_name("NAME")
            )
            .arg(Arg::new("package_version")
                .required(false)
                .multiple(false)
                .index(2)
                .value_name("VERSION")
                .about("Exact package version to build (string match)")
            )

            .arg(Arg::new("no_verification")
                .required(false)
                .multiple(false)
                .takes_value(false)
                .long("no-verify")
                .about("Skip hashsum check")
                .long_about(indoc::indoc!(r#"
                    Do not perform a hash sum check on all packages in the dependency tree before starting the build.
                "#))
            )
            .arg(Arg::new("no_lint")
                .required(false)
                .multiple(false)
                .takes_value(false)
                .long("no-lint")
                .about("Skip linting")
                .long_about(indoc::indoc!(r#"
                    Do not perform script linting before starting the build.
                "#))
            )

            .arg(Arg::new("staging_dir")
                .required(false)
                .multiple(false)
                .long("staging-dir")
                .takes_value(true)
                .value_name("PATH")
                .validator(dir_exists_validator)
                .about("Do not throw dice on staging directory name, but hardcode for this run.")
            )

            .arg(Arg::new("shebang")
                .required(false)
                .multiple(false)
                .long("shebang")
                .takes_value(true)
                .value_name("BANG")
                .about("Overwrite the configured shebang line")
            )

            .arg(Arg::new("env")
                .required(false)
                .multiple(true)
                .short('E')
                .long("env")
                .validator(env_pass_validator)
                .about("Pass environment variable to all build jobs")
                .long_about(indoc::indoc!(r#"
                    Pass these variables to each build job.
                    This argument expects \"key=value\" or name of variable available in ENV
                "#))
            )

            .arg(Arg::new("image")
                .required(true)
                .multiple(false)
                .takes_value(true)
                .value_name("IMAGE NAME")
                .short('I')
                .long("image")
                .about("Name of the docker image to use")
            )

            .arg(Arg::new("write-log-file")
                .required(false)
                .multiple(false)
                .long("write-log")
                .short('L')
                .about("Write log to disk as well")
                .long_about(indoc::indoc!(r#"
                    With this flag set, butido does not only write the build logs to database, but also to the configured
                    log directory.

                    The log of a build is written to `<log_dir>/<build id>.log`.
                "#))
            )
        )

        .subcommand(App::new("what-depends")
            .version(crate_version!())
            .about("List all packages that depend on a specific package")
            .arg(Arg::new("package_name")
                .required(true)
                .multiple(false)
                .index(1)
                .about("The name of the package")
            )
            .arg(Arg::new("dependency_type")
                .required(false)
                .multiple(true)
                .takes_value(true)
                .short('t')
                .long("type")
                .value_name("DEPENDENCY_TYPE")
                .possible_values(&[
                    IDENT_DEPENDENCY_TYPE_BUILD,
                    IDENT_DEPENDENCY_TYPE_RUNTIME,
                ])
                .default_values(&[
                    IDENT_DEPENDENCY_TYPE_BUILD,
                    IDENT_DEPENDENCY_TYPE_RUNTIME,
                ])
                .about("Specify which dependency types are to be checked. By default, all are checked")
            )
        )
        .subcommand(App::new("dependencies-of")
            .version(crate_version!())
            .alias("depsof")
            .about("List the depenendcies of a package")
            .arg(Arg::new("package_name")
                .required(true)
                .multiple(false)
                .index(1)
                .value_name("PACKAGE_NAME")
                .about("The name of the package")
            )
            .arg(Arg::new("package_version_constraint")
                .required(false)
                .multiple(false)
                .index(2)
                .value_name("VERSION_CONSTRAINT")
                .about("A version constraint to search for (optional), E.G. '=1.0.0'")
            )
            .arg(Arg::new("dependency_type")
                .required(false)
                .multiple(true)
                .takes_value(true)
                .short('t')
                .long("type")
                .value_name("DEPENDENCY_TYPE")
                .possible_values(&[
                    IDENT_DEPENDENCY_TYPE_BUILD,
                    IDENT_DEPENDENCY_TYPE_RUNTIME,
                ])
                .default_values(&[
                    IDENT_DEPENDENCY_TYPE_BUILD,
                    IDENT_DEPENDENCY_TYPE_RUNTIME,
                ])
                .about("Specify which dependency types are to be printed. By default, all are checked")
            )
        )
        .subcommand(App::new("versions-of")
            .version(crate_version!())
            .alias("versions")
            .about("List the versions of a package")
            .arg(Arg::new("package_name")
                .required(true)
                .multiple(false)
                .index(1)
                .value_name("PACKAGE_NAME")
                .about("The name of the package")
            )
        )
        .subcommand(App::new("env-of")
            .version(crate_version!())
            .alias("env")
            .about("Show the ENV configured for a package")
            .arg(Arg::new("package_name")
                .required(true)
                .multiple(false)
                .index(1)
                .value_name("PACKAGE_NAME")
                .about("The name of the package")
            )
            .arg(Arg::new("package_version_constraint")
                .required(true)
                .multiple(false)
                .index(2)
                .value_name("VERSION_CONSTRAINT")
                .about("A version constraint to search for (optional), E.G. '=1.0.0'")
            )
        )

        .subcommand(App::new("find-artifact")
            .version(crate_version!())
            .about("Find artifacts for packages")
            .arg(Arg::new("package_name_regex")
                .required(true)
                .multiple(false)
                .index(1)
                .value_name("REGEX")
                .about("The regex to match the package name against")
            )
            .arg(Arg::new("package_version_constraint")
                .required(false)
                .multiple(false)
                .index(2)
                .value_name("VERSION_CONSTRAINT")
                .about("A version constraint to search for (optional), E.G. '=1.0.0'")
            )
            .arg(Arg::new("no_script_filter")
                .long("no-script-filter")
                .short('S')
                .required(false)
                .multiple(false)
                .takes_value(false)
                .about("Don't check for script equality. Can cause unexact results.")
            )
            .arg(Arg::new("staging_dir")
                .required(false)
                .multiple(false)
                .long("staging-dir")
                .takes_value(true)
                .value_name("PATH")
                .validator(dir_exists_validator)
                .about("Also consider this staging dir when searching for artifacts")
            )
            .arg(Arg::new("env_filter")
                .required(false)
                .multiple(true)
                .long("env")
                .short('E')
                .takes_value(true)
                .value_name("KV")
                .validator(env_pass_validator)
                .about("Filter for this \"key=value\" environment variable")
            )
            .arg(Arg::new("image")
                .required(false)
                .multiple(false)
                .long("image")
                .short('I')
                .takes_value(true)
                .value_name("IMAGE")
                .about("Only list artifacts that were built on IMAGE")
            )
        )

        .subcommand(App::new("find-pkg")
            .version(crate_version!())
            .about("Find a package by regex")
            .arg(Arg::new("package_name_regex")
                .required(true)
                .multiple(false)
                .index(1)
                .value_name("REGEX")
                .about("The regex to match the package name against")
            )
            .arg(Arg::new("package_version_constraint")
                .required(false)
                .multiple(false)
                .index(2)
                .value_name("VERSION_CONSTRAINT")
                .about("A version constraint to search for (optional), E.G. '=1.0.0'")
            )

            .arg(Arg::new("terse")
                .required(false)
                .multiple(false)
                .long("terse")
                .short('t')
                .about("Do not use the fancy format, but simply <name> <version>")
            )

            .arg(Arg::new("show_all")
                .required(false)
                .multiple(false)
                .long("all")
                .short('A')
                .about("Same as: -SDpEFPs --denied-images --allowed-images (all flags enabled)")
            )

            .arg(Arg::new("show_sources")
                .required(false)
                .multiple(false)
                .long("source")
                .alias("sources")
                .short('S')
                .about("Show the sources of the package")
            )

            .arg(Arg::new("show_dependencies")
                .required(false)
                .multiple(false)
                .long("dependencies")
                .alias("deps")
                .short('D')
                .about("Show the dependencies of the package")
            )
            .arg(Arg::new("dependency_type")
                .required(false)
                .multiple(true)
                .takes_value(true)
                .long("dependency-type")
                .value_name("DEPENDENCY_TYPE")
                .possible_values(&[
                    IDENT_DEPENDENCY_TYPE_BUILD,
                    IDENT_DEPENDENCY_TYPE_RUNTIME,
                ])
                .default_values(&[
                    IDENT_DEPENDENCY_TYPE_BUILD,
                    IDENT_DEPENDENCY_TYPE_RUNTIME,
                ])
                .about("Specify which dependency types are to print.")
            )

            .arg(Arg::new("show_patches")
                .required(false)
                .multiple(false)
                .long("patches")
                .short('p')
                .about("Show the patches of the package")
            )

            .arg(Arg::new("show_env")
                .required(false)
                .multiple(false)
                .long("env")
                .short('E')
                .about("Show the environment of the package")
            )

            .arg(Arg::new("show_flags")
                .required(false)
                .multiple(false)
                .long("flags")
                .short('F')
                .about("Show the flags of the package")
            )

            .arg(Arg::new("show_allowed_images")
                .required(false)
                .multiple(false)
                .long("allowed-images")
                .about("Show the images on which the package is only allowed to be built")
            )

            .arg(Arg::new("show_denied_images")
                .required(false)
                .multiple(false)
                .long("denied-images")
                .about("Show the images on which the package is not allowed to be built")
            )

            .arg(Arg::new("show_phases")
                .required(false)
                .multiple(false)
                .long("phases")
                .short('P')
                .about("Show the phases of the script of the package")
            )

            .arg(Arg::new("show_script")
                .required(false)
                .multiple(false)
                .long("script")
                .short('s')
                .about("Show the script of the package")
            )
            .arg(script_arg_line_numbers())
            .arg(script_arg_no_line_numbers())
            .arg(script_arg_highlight())
            .arg(script_arg_no_highlight())

        )
        .subcommand(App::new("source")
            .version(crate_version!())
            .about("Handle package sources")
            .subcommand(App::new("verify")
                .version(crate_version!())
                .about("Hash-check all source files")
                .arg(Arg::new("package_name")
                    .required(false)
                    .multiple(false)
                    .index(1)
                    .value_name("PKG")
                    .about("Verify the sources of this package (optional, if left out, all packages are checked)")
                )
                .arg(Arg::new("package_version")
                    .required(false)
                    .multiple(false)
                    .index(2)
                    .value_name("VERSION")
                    .about("Verify the sources of this package version (optional, if left out, all packages are checked)")
                )

                .arg(Arg::new("matching")
                    .required(false)
                    .multiple(false)
                    .long("matching")
                    .takes_value(true)
                    .value_name("REGEX")
                    .about("Verify all packages where the package name matches REGEX")
                )

                .group(ArgGroup::new("verify-one-or-many")
                    .args(&["package_name", "matching"])
                    .required(true)
                )
            )
            .subcommand(App::new("list-missing")
                .version(crate_version!())
                .about("List packages where the source is missing")
            )
            .subcommand(App::new("url")
                .version(crate_version!())
                .about("Show the URL of the source of a package")
                .arg(Arg::new("package_name")
                    .required(false)
                    .multiple(false)
                    .index(1)
                    .value_name("PKG")
                    .about("Verify the sources of this package (optional, if left out, all packages are checked)")
                )
                .arg(Arg::new("package_version")
                    .required(false)
                    .multiple(false)
                    .index(2)
                    .value_name("VERSION")
                    .about("Verify the sources of this package version (optional, if left out, all packages are checked)")
                )
            )
            .subcommand(App::new("download")
                .version(crate_version!())
                .about("Download the source for one or multiple packages")
                .arg(Arg::new("package_name")
                    .required(false)
                    .multiple(false)
                    .index(1)
                    .value_name("PKG")
                    .about("Download the sources of this package")
                )
                .arg(Arg::new("package_version")
                    .required(false)
                    .multiple(false)
                    .index(2)
                    .value_name("VERSION_CONSTRAINT")
                    .about("Download the sources of this package version (optional, if left out, all packages are downloaded)")
                )
                .arg(Arg::new("force")
                    .required(false)
                    .multiple(false)
                    .long("force")
                    .about("Overwrite existing cache entry")
                )

                .arg(Arg::new("matching")
                    .required(false)
                    .multiple(false)
                    .long("matching")
                    .takes_value(true)
                    .value_name("REGEX")
                    .about("Download all packages matching a regex with their name")
                )

                .group(ArgGroup::new("download-one-or-many")
                    .args(&["package_name", "matching"])
                    .required(true)
                )

                .arg(Arg::new("timeout")
                    .required(false)
                    .multiple(false)
                    .long("timeout")
                    .takes_value(true)
                    .value_name("TIMEOUT")
                    .about("Set timeout for download in seconds")
                )
            )
            .subcommand(App::new("of")
                .version(crate_version!())
                .about("Get the pathes of the sources of a package")
                .arg(Arg::new("package_name")
                    .required(false)
                    .multiple(false)
                    .index(1)
                    .value_name("PKG")
                    .about("Get the source file pathes for this package")
                )
                .arg(Arg::new("package_version")
                    .required(false)
                    .multiple(false)
                    .index(2)
                    .value_name("VERSION")
                    .about("Get the source file pathes for the package in this version")
                )
            )
        )

        .subcommand(App::new("release")
            .version(crate_version!())
            .about("Manage artifact releases")
            .subcommand(App::new("rm")
                .version(crate_version!())
                .about("Remove release artifacts")
                .long_about(indoc::indoc!(r#"
                    Removes a released artifact from the release store and deletes the according database entry.

                    This command asks interactively whether you want to delete data.
                    This can't be turned off.
                "#))
                .arg(Arg::new("release_store_name")
                    .required(true)
                    .multiple(false)
                    .long("from")
                    .value_name("RELEASE_STORE_NAME")
                    .about("Release store name to remove release from")
                )

                .arg(Arg::new("package_name")
                    .required(false)
                    .multiple(false)
                    .index(1)
                    .value_name("PKG")
                    .about("The name of the package")
                    .requires("package_version")
                )

                .arg(Arg::new("package_version")
                    .required(false)
                    .multiple(false)
                    .index(2)
                    .value_name("VERSION")
                    .about("The exact version of the package (string match)")
                    .requires("package_name")
                )
            )

            .subcommand(App::new("new")
                .version(crate_version!())
                .about("Release artifacts")
                .arg(Arg::new("submit_uuid")
                    .required(true)
                    .multiple(false)
                    .index(1)
                    .value_name("SUBMIT")
                    .about("The submit uuid from which to release a package")
                )
                .arg(Arg::new("release_store_name")
                    .required(true)
                    .multiple(false)
                    .long("to")
                    .value_name("RELEASE_STORE_NAME")
                    .about("Release store name to release to")
                    .long_about(indoc::indoc!(r#"
                        Butido can release to different release stores, based on this CLI flag.
                        The release stores that are available must be listed in the configuration.
                    "#))
                )
                .arg(Arg::new("package_name")
                    .required(false)
                    .multiple(false)
                    .index(2)
                    .value_name("PKG")
                    .about("The name of the package")
                    .conflicts_with("all-packages")
                )
                .arg(Arg::new("all-packages")
                    .required(false)
                    .multiple(false)
                    .long("all")
                    .about("Release all packages")
                    .conflicts_with("package_name")
                )
                .group(ArgGroup::new("package")
                    .args(&["package_name", "all-packages"])
                    .required(true) // one of these is required
                )
                .arg(Arg::new("package_version")
                    .required(false)
                    .multiple(false)
                    .index(3)
                    .value_name("VERSION")
                    .about("The exact version of the package (string match)")
                )
                .arg(Arg::new("package_do_update")
                    .required(false)
                    .multiple(false)
                    .long("update")
                    .about("Do update a package if it already exists in the release store")
                )
                .arg(Arg::new("noninteractive")
                    .required(false)
                    .multiple(false)
                    .long("non-interactive")
                    .about("Dont be interactive (only with --update at the moment)")
                    .requires("package_do_update")
                )
                .arg(Arg::new("quiet")
                    .required(false)
                    .multiple(false)
                    .long("quiet")
                    .short('q')
                    .about("Don't print pathes to released filesfiles  after releases are complete")
                )
            )

        )

        .subcommand(App::new("lint")
            .version(crate_version!())
            .about("Lint the package script of one or multiple packages")
            .arg(Arg::new("package_name")
                .required(false)
                .multiple(false)
                .index(1)
                .value_name("NAME")
                .about("Package name to lint (if not present, every package will be linted")
            )
            .arg(Arg::new("package_version")
                .required(false)
                .multiple(false)
                .index(2)
                .value_name("VERSION_CONSTRAINT")
                .about("A version constraint to search for (optional), E.G. '=1.0.0'")
            )
        )

        .subcommand(App::new("tree-of")
            .version(crate_version!())
            .about("Print the dependency tree of one or multiple packages")
            .arg(Arg::new("package_name")
                .required(true)
                .multiple(false)
                .index(1)
                .value_name("NAME")
                .about("Package name to lint (if not present, every package will be linted")
            )
            .arg(Arg::new("package_version")
                .required(false)
                .multiple(false)
                .index(2)
                .value_name("VERSION_CONSTRAINT")
                .about("A version constraint to search for (optional), E.G. '=1.0.0'")
            )
            .arg(Arg::new("image")
                .required(false)
                .multiple(false)
                .takes_value(true)
                .value_name("IMAGE NAME")
                .short('I')
                .long("image")
                .about("Name of the docker image to use")
                .long_about(indoc::indoc!(r#"
                    Name of the docker image to use.

                    Required because tree might look different on different images because of
                    conditions on dependencies.
                "#))
            )
            .arg(Arg::new("env")
                .required(false)
                .multiple(true)
                .short('E')
                .long("env")
                .validator(env_pass_validator)
                .about("Additional env to be passed when building packages")
                .long_about(indoc::indoc!(r#"
                    Additional env to be passed when building packages.

                    Required because tree might look different on different images because of
                    conditions on dependencies.
                "#))
            )
        )

        .subcommand(App::new("metrics")
            .version(crate_version!())
            .about("Print metrics about butido")
        )

        .subcommand(App::new("endpoint")
            .version(crate_version!())
            .about("Endpoint maintentance commands")
            .arg(Arg::new("endpoint_name")
                .required(false)
                .multiple(false)
                .index(1)
                .value_name("ENDPOINT_NAME")
                .about("Endpoint to talk to, or all if not given")
            )

            .subcommand(App::new("ping")
                .version(crate_version!())
                .about("Ping the endpoint(s)")
                .arg(Arg::new("ping_n")
                    .required(false)
                    .multiple(false)
                    .long("times")
                    .short('n')
                    .value_name("N")
                    .default_value("10")
                    .about("How often to ping")
                )
                .arg(Arg::new("ping_sleep")
                    .required(false)
                    .multiple(false)
                    .long("sleep")
                    .value_name("N")
                    .default_value("1")
                    .about("How long to sleep between pings")
                )
            )
            .subcommand(App::new("stats")
                .version(crate_version!())
                .about("Get stats for the endpoint(s)")
                .arg(Arg::new("csv")
                    .required(false)
                    .multiple(false)
                    .long("csv")
                    .takes_value(false)
                    .about("Format output as CSV")
                )
            )
            .subcommand(App::new("containers")
                .version(crate_version!())
                .about("Work with the containers of the endpoint(s)")
                .subcommand(App::new("prune")
                    .version(crate_version!())
                    .about("Remove exited containers")
                    .arg(arg_older_than_date("Prune only containers older than DATE"))
                    .arg(arg_newer_than_date("Prune only containers newer than DATE"))
                )
                .subcommand(App::new("stop")
                    .version(crate_version!())
                    .about("Stop running containers")
                    .arg(arg_older_than_date("Stop only containers older than DATE"))
                    .arg(arg_newer_than_date("Stop only containers newer than DATE"))
                    .arg(Arg::new("timeout")
                        .required(false)
                        .multiple(false)
                        .long("timeout")
                        .short('t')
                        .takes_value(true)
                        .value_name("TIMEOUT")
                        .about("Timeout in seconds")
                        .validator(parse_u64)
                    )
                )
                .subcommand(App::new("list")
                    .version(crate_version!())
                    .about("List the containers and stats about them")
                    .arg(Arg::new("csv")
                        .required(false)
                        .multiple(false)
                        .long("csv")
                        .takes_value(false)
                        .about("Format output as CSV")
                    )

                    .arg(Arg::new("list_stopped")
                        .required(false)
                        .multiple(false)
                        .long("list-stopped")
                        .takes_value(false)
                        .about("List stopped containers too")
                    )

                    .arg(Arg::new("filter_image")
                        .required(false)
                        .multiple(false)
                        .long("image")
                        .takes_value(true)
                        .value_name("IMAGE")
                        .about("List only containers of IMAGE")
                    )

                    .arg(arg_older_than_date("List only containers older than DATE"))
                    .arg(arg_newer_than_date("List only containers newer than DATE"))
                )
                .subcommand(App::new("top")
                    .version(crate_version!())
                    .about("List the processes of all containers")
                    .arg(Arg::new("csv")
                        .required(false)
                        .multiple(false)
                        .long("csv")
                        .takes_value(false)
                        .about("List top output as CSV")
                    )
                    .arg(Arg::new("limit")
                        .required(false)
                        .multiple(false)
                        .long("limit")
                        .takes_value(true)
                        .value_name("LIMIT")
                        .about("Only list LIMIT processes for each container")
                        .validator(parse_usize)
                    )
                )
            )
            .subcommand(App::new("container")
                .version(crate_version!())
                .about("Work with a specific container")
                .arg(Arg::new("container_id")
                    .required(true)
                    .multiple(false)
                    .index(1)
                    .takes_value(true)
                    .value_name("CONTAINER_ID")
                    .about("Work with container CONTAINER_ID")
                )
                .subcommand(App::new("top")
                    .version(crate_version!())
                    .about("List the container processes")
                    .arg(Arg::new("csv")
                        .required(false)
                        .multiple(false)
                        .long("csv")
                        .takes_value(false)
                        .about("List top output as CSV")
                    )
                )
                .subcommand(App::new("kill")
                    .version(crate_version!())
                    .about("Kill the container")
                    .arg(Arg::new("signal")
                        .required(false)
                        .multiple(false)
                        .index(1)
                        .takes_value(true)
                        .value_name("SIGNAL")
                        .about("Kill container with this signal")
                    )
                )
                .subcommand(App::new("delete")
                    .version(crate_version!())
                    .about("Delete the container")
                )
                .subcommand(App::new("start")
                    .version(crate_version!())
                    .about("Start the container")
                )
                .subcommand(App::new("stop")
                    .version(crate_version!())
                    .about("Stop the container")
                    .arg(Arg::new("timeout")
                        .required(false)
                        .multiple(false)
                        .long("timeout")
                        .takes_value(true)
                        .value_name("DURATION")
                        .about("Timeout")
                    )
                )
                .subcommand(App::new("exec")
                    .version(crate_version!())
                    .about("Execute commands in the container")
                    .arg(Arg::new("commands")
                        .required(true)
                        .multiple(true)
                        .index(1)
                        .takes_value(true)
                        .value_name("CMD")
                        .about("Commands to execute in the container")
                        .long_about(indoc::indoc!(r#"
                            Execute a command in the container.

                            This does not handle TTY forwarding, so you cannot execute interactive commands in the container (e.g. htop).
                            For executing interactive things, you have to login to the container.
                        "#))
                    )
                )

                .subcommand(App::new("inspect")
                    .version(crate_version!())
                    .about("Display details about the container")
                    .long_about("Display details about the container. Do not assume the output format to be stable.")
                )
            )
            .subcommand(App::new("images")
                .version(crate_version!())
                .about("Query images on endpoint(s)")
                .subcommand(App::new("list")
                    .version(crate_version!())
                    .about("List images on endpoint(s)")
                    .arg(Arg::new("csv")
                        .required(false)
                        .multiple(false)
                        .long("csv")
                        .takes_value(false)
                        .about("List top output as CSV")
                    )
                )
                .subcommand(App::new("verify-present")
                    .version(crate_version!())
                    .about("Verify that all configured images are present on endpoint(s)")
                    .arg(Arg::new("csv")
                        .required(false)
                        .multiple(false)
                        .long("csv")
                        .takes_value(false)
                        .about("List top output as CSV")
                    )
                )
            )
        )
}

fn script_arg_line_numbers<'a>() -> clap::Arg<'a> {
    Arg::new("script_line_numbers")
        .required(false)
        .multiple(false)
        .long("line-numbers")
        .about("Print script with line numbers (default)")
        .conflicts_with("no_script_line_numbers")
}

fn script_arg_no_line_numbers<'a>() -> clap::Arg<'a> {
    Arg::new("no_script_line_numbers")
        .required(false)
        .multiple(false)
        .long("no-line-numbers")
        .about("Print script without line numbers")
        .conflicts_with("script_line_numbers")
}

fn script_arg_highlight<'a>() -> clap::Arg<'a> {
    Arg::new("script_highlight")
        .required(false)
        .multiple(false)
        .long("highlighting")
        .alias("highlight")
        .about("Print script with highlighting (default)")
        .conflicts_with("no_script_highlight")
}

fn script_arg_no_highlight<'a>() -> clap::Arg<'a> {
    Arg::new("no_script_highlight")
        .required(false)
        .multiple(false)
        .long("no-highlighting")
        .alias("no-highlight")
        .about("Print script without highlighting")
        .conflicts_with("script_highlight")
}

/// Naive check whether 's' is a 'key=value' pair or an existing environment variable
///
/// TODO: Clean up this spaghetti code
fn env_pass_validator(s: &str) -> Result<(), String> {
    use crate::util::parser::*;
    let parser = {
        let key = (letters() + ((letters() | numbers() | under()).repeat(0..)))
            .collect()
            .convert(|b| String::from_utf8(b.to_vec()));

        let val = nonempty_string_with_optional_quotes()
            .collect()
            .convert(|b| String::from_utf8(b.to_vec()));

        (key + equal() + val).map(|((k, _), v)| (k, v))
    };

    match parser.parse(s.as_bytes()).map_err(|e| e.to_string()) {
        Err(s) => {
            log::error!("Error during validation: '{}' is not a key-value pair", s);
            Err(s)
        }
        Ok((k, v)) => {
            log::debug!("Env pass valiation: '{}={}'", k, v);
            Ok(())
        }
    }
}

fn dir_exists_validator(s: &str) -> Result<(), String> {
    if PathBuf::from(&s).is_dir() {
        Ok(())
    } else {
        Err(format!("Directory does not exist: {}", s))
    }
}

fn arg_older_than_date(about: &str) -> Arg<'_> {
    Arg::new("older_than")
        .required(false)
        .multiple(false)
        .long("older-than")
        .takes_value(true)
        .value_name("DATE")
        .about(about)
        .long_about(r#"
            DATE can be a freeform date, for example '2h'
            It can also be a exact date: '2020-01-01 00:12:45'
            If the hour-minute-second part is omitted, " 00:00:00" is appended automatically.

            Supported suffixes:

                nsec, ns -- nanoseconds
                usec, us -- microseconds
                msec, ms -- milliseconds
                seconds, second, sec, s
                minutes, minute, min, m
                hours, hour, hr, h
                days, day, d
                weeks, week, w
                months, month, M -- defined as 30.44 days
                years, year, y -- defined as 365.25 days

        "#)
        .validator(parse_date_from_string)
}

fn arg_newer_than_date(about: &str) -> Arg<'_> {
    Arg::new("newer_than")
        .required(false)
        .multiple(false)
        .long("newer-than")
        .takes_value(true)
        .value_name("DATE")
        .about(about)
        .long_about(r#"
            DATE can be a freeform date, for example '2h'
            It can also be a exact date: '2020-01-01 00:12:45'
            If the hour-minute-second part is omitted, " 00:00:00" is appended automatically.

            Supported suffixes:

                nsec, ns -- nanoseconds
                usec, us -- microseconds
                msec, ms -- milliseconds
                seconds, second, sec, s
                minutes, minute, min, m
                hours, hour, hr, h
                days, day, d
                weeks, week, w
                months, month, M -- defined as 30.44 days
                years, year, y -- defined as 365.25 days

        "#)
        .validator(parse_date_from_string)
}

fn parse_date_from_string(s: &str) -> std::result::Result<(), String> {
    humantime::parse_duration(s)
        .map_err(|e| e.to_string())
        .map(|_| ())
        .or_else(|_| {
            humantime::parse_rfc3339_weak(s)
                .map_err(|e| e.to_string())
                .map(|_| ())
        })
        .or_else(|_| {
            let s = format!("{} 00:00:00", s);
            humantime::parse_rfc3339_weak(&s)
                .map_err(|e| e.to_string())
                .map(|_| ())
        })
}

fn parse_usize(s: &str) -> std::result::Result<(), String> {
    usize::from_str(s) .map_err(|e| e.to_string()).map(|_| ())
}

fn parse_u64(s: &str) -> std::result::Result<(), String> {
    u64::from_str(s).map_err(|e| e.to_string()).map(|_| ())
}

#[cfg(test)]
mod tests {
    use super::env_pass_validator;

    #[test]
    fn test_env_pass_validator_1() {
        assert!(env_pass_validator("foo=\"bar\"").is_ok());
    }

    #[test]
    fn test_env_pass_validator_2() {
        assert!(env_pass_validator("foo=bar").is_ok());
    }

    #[test]
    fn test_env_pass_validator_3() {
        assert!(env_pass_validator("foo=\"1\"").is_ok());
    }

    #[test]
    fn test_env_pass_validator_4() {
        assert!(env_pass_validator("foo=1").is_ok());
    }

    #[test]
    fn test_env_pass_validator_5() {
        assert!(env_pass_validator("FOO=\"bar\"").is_ok());
    }

    #[test]
    fn test_env_pass_validator_6() {
        assert!(env_pass_validator("FOO=bar").is_ok());
    }

    #[test]
    fn test_env_pass_validator_7() {
        assert!(env_pass_validator("FOO=\"1\"").is_ok());
    }

    #[test]
    fn test_env_pass_validator_8() {
        assert!(env_pass_validator("FOO=1").is_ok());
    }

    #[test]
    fn test_env_pass_validator_9() {
        assert!(env_pass_validator("1=1").is_err());
    }

    #[test]
    fn test_env_pass_validator_10() {
        assert!(env_pass_validator("=").is_err());
    }

    #[test]
    fn test_env_pass_validator_11() {
        assert!(env_pass_validator("a=").is_err());
    }

    #[test]
    fn test_env_pass_validator_12() {
        assert!(env_pass_validator("=a").is_err());
    }

    #[test]
    fn test_env_pass_validator_13() {
        assert!(env_pass_validator("a").is_err());
    }

    #[test]
    fn test_env_pass_validator_14() {
        assert!(env_pass_validator("avjasva").is_err());
    }

    #[test]
    fn test_env_pass_validator_15() {
        assert!(env_pass_validator("123").is_err());
    }
}