|
8 | 8 | description about the best solution arrived at.
|
9 | 9 | """
|
10 | 10 |
|
| 11 | +from argparse import ArgumentParser |
| 12 | + |
11 | 13 | import os
|
12 | 14 | import subprocess
|
13 | 15 | import sys
|
@@ -77,12 +79,23 @@ def gather_stats(self, iters):
|
77 | 79 | print("Done. Find stats in %s" % self.__make_data_dir_path())
|
78 | 80 |
|
79 | 81 | if __name__ == "__main__":
|
80 |
| - if len(sys.argv) != 3: |
81 |
| - print("Usage: python3 %s <script.path> <iters>" % __file__) |
82 |
| - exit(1) |
| 82 | + parser = ArgumentParser(description="Run and gather stats for Clever Algorithms") |
| 83 | + parser.add_argument( |
| 84 | + "script-path", nargs=1, type=str, |
| 85 | + help="The script to run. Use package.notation for Python scripts and directory/notation for Ruby scripts." |
| 86 | + ) |
| 87 | + parser.add_argument( |
| 88 | + "--limit", "-l", required=True, type=int, default=100, |
| 89 | + help="The number of iterations to run the script." |
| 90 | + ) |
| 91 | + parser.add_argument( |
| 92 | + "--encoding", "-e", required=False, type=str, default="utf-8", |
| 93 | + help="The expected encoding of the script output." |
| 94 | + ) |
| 95 | + args = vars(parser.parse_args()) |
83 | 96 |
|
84 |
| - limit = int(sys.argv[2]) |
85 |
| - script_path = sys.argv[1] |
| 97 | + limit = int(args["limit"]) |
| 98 | + script_path = args["script-path"][0] |
86 | 99 |
|
87 |
| - runner = StatRunner(script_path) |
| 100 | + runner = StatRunner(script_path, output_encoding=args["encoding"]) |
88 | 101 | runner.gather_stats(limit)
|
0 commit comments