Skip to content

Commit 4d4c52a

Browse files
committed
Added the --verbose command line option
1 parent f52761a commit 4d4c52a

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

dice/__init__.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,39 @@
77
import dice.grammar
88
import dice.utilities
99

10-
__all__ = ['parse', 'roll', 'main', 'ParseException']
10+
__all__ = ['roll', 'main', 'ParseException']
1111
__author__ = "Sam Clements <[email protected]>"
12-
__version__ = "0.2.0"
12+
__version__ = "0.2.1"
1313

1414
from pyparsing import ParseException
1515

1616
parser = argparse.ArgumentParser()
1717
parser.add_argument(
18-
'-v', '--version', action='version',
18+
'-V', '--version', action='version',
1919
version='dice v{0} by {1}'.format(__version__, __author__))
20+
parser.add_argument(
21+
'-v', '--verbose', action='store_true',
22+
help="show additional output")
2023
parser.add_argument(
2124
'expression',
2225
help="the expression to parse and roll")
2326

24-
def _(obj):
25-
print(obj)
26-
return obj
27-
2827
def parse(string, grammar):
2928
"""Returns an AST parsed from an expression"""
30-
return _(grammar.parseString(string, parseAll=True))
29+
return grammar.parseString(string, parseAll=True)
3130

32-
def evaluate(string, grammar):
31+
def evaluate(string, grammar, **options):
3332
"""Parse and then evaluate a string with a grammar"""
34-
return _([element.evaluate() for element in parse(string, grammar)])
33+
return [e.evaluate(**options) for e in parse(string, grammar)]
3534

36-
def roll(string):
35+
def roll(string, verbose=False):
3736
"""Parses and evaluates an expression"""
38-
return evaluate(string, dice.grammar.expression)
37+
return evaluate(string, grammar=dice.grammar.expression, verbose=verbose)
3938

4039
def main(argv=None):
4140
args = parser.parse_args(argv)
42-
result = roll(args.expression)
43-
print("Result:", dice.utilities.single(result))
41+
result = roll(args.expression, verbose=args.verbose)
42+
result = dice.utilities.single(result)
43+
if args.verbose:
44+
print("Result:", end=" ")
4445
return result

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name = 'dice',
8-
version = '0.2.0',
8+
version = '0.2.1',
99

1010
author = "Sam Clements",
1111
author_email = "[email protected]",

0 commit comments

Comments
 (0)