ldcheck.py

changeset 26
7c263b864371
parent 21
8006fb8cdb77
child 32
75f44d3063da
--- a/ldcheck.py	Mon Jan 22 21:04:53 2018 +0200
+++ b/ldcheck.py	Mon Jan 22 21:21:53 2018 +0200
@@ -71,15 +71,41 @@
     def quadrilaterals(self):
         yield from self.filter_by_type(linetypes.Quadrilateral)
 
+import argparse
+class ListTestSuiteAction(argparse.Action):
+    def __init__(self, option_strings, dest, nargs = None, **kwargs):
+        super().__init__(option_strings, dest, nargs = 0, **kwargs)
+    def __call__(self, *args, **kwargs):
+        from testsuite import load_tests
+        from sys import exit
+        from re import sub
+        test_suite = load_tests()
+        for test_name in sorted(test_suite['tests'].keys()):
+            test_function = test_suite['tests'][test_name]
+            help = sub(r'\s+', ' ', test_function.__doc__ or '').strip()
+            print(test_name + ': ' + help)
+        exit(0)
+
 if __name__ == '__main__':
     from sys import argv
+    parser = argparse.ArgumentParser()
+    parser.add_argument('filename')
+    parser.add_argument('--list',
+        action = ListTestSuiteAction,
+        help = 'Lists all possible checks and exit',
+    )
+    args = parser.parse_args()
     config = load_config('ldcheck.cfg')
     for ldconfig_ldr_path in find_ldconfig_ldr_paths(config):
         with ldconfig_ldr_path.open() as ldconfig_ldr:
             load_colours(ldconfig_ldr)
-    with open(argv[1], 'r') as file:
+    with open(args.filename) as file:
         from os.path import basename
-        model = read_ldraw(file, name = basename(argv[1]), config = config)
+        model = read_ldraw(
+            file,
+            name = basename(args.filename),
+            config = config,
+        )
         from testsuite import load_tests, check_model, format_report
         test_suite = load_tests()
         report = check_model(model, test_suite)

mercurial