olinox пре 8 година
родитељ
комит
ba6e222444
2 измењених фајлова са 52 додато и 0 уклоњено
  1. 7 0
      nose2.cfg
  2. 45 0
      roll.py

+ 7 - 0
nose2.cfg

@@ -0,0 +1,7 @@
+[unittest]
+with-coverage = True
+
+[coverage]
+always-on = True
+coverage = dice
+coverage-report = html

+ 45 - 0
roll.py

@@ -0,0 +1,45 @@
+"""
+Usage:
+    roll [options] <expr>
+
+Options:
+    -s               Numeric score only
+
+    -h --help        Displays help message
+    --version        Displays current pydice version
+"""
+import sys
+
+import dice
+
+def print_ex(string, exit_code=0):
+    """ print and exit """
+    print(string)
+    sys.exit(exit_code)
+
+# Parse arguments
+args = sys.argv[1:]
+
+if "-h" in args:
+    print_ex(__doc__)
+
+if "-v" in args:
+    print_ex("pydice {}".format(dice.__VERSION__))
+
+score_only = False
+if "-s" in args:
+    score_only = True
+    args.remove("-s")
+
+if len(args) != 1:
+    print_ex("pydice CLI: invalid arguments\n" + __doc__, 1)
+
+pattern_string = args[0]
+
+# Run pydice
+ps = dice.roll(pattern_string)
+
+if score_only:
+    print(ps)
+else:
+    print("{}\t({})".format(ps, ps.format()))