Coverage for venv1 / lib / python3.10 / site-packages / combinatrix / cli.py: 0%
42 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-04 09:41 +0100
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-04 09:41 +0100
1import argparse
2from combinatrix.core import convert_csv, fromcsv, fromjsonfile
5def main():
6 parser = argparse.ArgumentParser(prog="combinatrix",
7 description="Conbinatrix: Produce a full set of variations of a set of parameters, according to a provided set of rules \
8 for the values of those parameters, any inter-constraints/conditions on them.")
10 parser.add_argument("input", help="Source input file; can be either CSV or JSON, and should end with either .csv or .json")
11 parser.add_argument("-c", "--csv", action="store_true", help="if the input file does not end with .csv but is a CSV, use this flag to force that format")
12 parser.add_argument("-j", "--json", action="store_true", help="if the input file does not end with .csv but is a CSV, use this flag to force that format")
13 parser.add_argument("-m", "--matrix", help="output file path for matrix. If omitted, the matrix will not be generated")
14 parser.add_argument("-s", "--settings", help="output file path for JSON settings, if this is a conversion from a CSV settings file")
16 args = parser.parse_args()
18 if not args.input:
19 print("You must specify an input file")
20 parser.print_help()
21 exit()
23 if args.csv and args.json:
24 print("Specify either -c/--csv or -j/--json, or neither, but not both")
25 parser.print_help()
26 exit()
28 is_csv = args.csv
29 is_json = args.json
30 if not is_csv and not is_json:
31 is_csv = args.input.endswith(".csv")
32 is_json = args.input.endswith(".json")
34 if not is_csv and not is_json:
35 print("Unable to determine the format of the input. Please ensure you have a file which ends with .csv or .json, or force the format via -c/-j")
36 parser.print_help()
37 exit()
39 if not args.matrix and not args.settings:
40 print("You must specify at least one output file with -m and/or -s")
41 parser.print_help()
42 exit()
44 # if we've been given a csv, and the path to output the settings, but not a path to output the matrix, then just
45 # covert the csv
46 if is_csv and args.settings and not args.matrix:
47 convert_csv(args.input, args.settings)
49 # if we've been given a csv, and the path to the output matrix, then do a full conversion to csv. If we've also
50 # been provided with a path to the settings, these will get written, otherwise they won't
51 elif is_csv and args.matrix:
52 fromcsv(args.input, args.matrix, args.settings)
54 # if we've been given json, and the path to the output matrix, then do a conversion to the matrix.
55 elif is_json and args.matrix:
56 fromjsonfile(input, args.matrix)
58 else:
59 print("Unable to find a suitable path to execute")
60 parser.print_help()
61 exit()
64if __name__ == "__main__":
65 main()