Skip to content

Commit c0797cc

Browse files
committed
Add command line args.
1 parent 66d126e commit c0797cc

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

python/stat_runner.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
description about the best solution arrived at.
99
"""
1010

11+
from argparse import ArgumentParser
12+
1113
import os
1214
import subprocess
1315
import sys
@@ -77,12 +79,23 @@ def gather_stats(self, iters):
7779
print("Done. Find stats in %s" % self.__make_data_dir_path())
7880

7981
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())
8396

84-
limit = int(sys.argv[2])
85-
script_path = sys.argv[1]
97+
limit = int(args["limit"])
98+
script_path = args["script-path"][0]
8699

87-
runner = StatRunner(script_path)
100+
runner = StatRunner(script_path, output_encoding=args["encoding"])
88101
runner.gather_stats(limit)

0 commit comments

Comments
 (0)