Skip to content

Commit

Permalink
Apply style fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Hunter <[email protected]>
  • Loading branch information
ianfhunter authored Nov 17, 2023
1 parent f6934bb commit 884b22c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/python/code/gnoll/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def extract_from_dice_file(lines, seperator):
finally:
if not keep_temp_file:
if verbose:
print("Deleting:", out_file)
print("Deleting:", out_file)

os.remove(die_file)


Expand Down
62 changes: 40 additions & 22 deletions src/python/code/gnoll/__main__.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,57 @@
'''Roll some dice with GNOLL.'''
"""Roll some dice with GNOLL."""

import sys
import argparse
import gnoll

import sys, argparse, gnoll

def parse_cmdline_args(args):
"""Extract values from the commandline
@param args - the arguments from the commandline (excluding the python3 call)
"""
p = argparse.ArgumentParser(
description = __doc__,
usage = 'python3 -m gnoll [options] EXPR',
add_help = False)
description=__doc__,
usage='python3 -m gnoll [options] EXPR',
add_help=False)


p.add_argument('EXPR', nargs = '+',
help = 'a dice expression to evaluate '
'(multiple arguments will be joined with spaces)')
p.add_argument(
'EXPR',
nargs='+',
help='a dice expression to evaluate (multiple arguments will be joined with spaces)'
)

g = p.add_argument_group('main options')
g.add_argument('-h', '--help', action = 'help',
help = 'show this help message and exit')
g.add_argument('-b', '--breakdown', action = 'store_true',
help = 'show a breakdown into individual dice')
g.add_argument('--no-builtins', action = 'store_true',
help = 'disable built-in macros')
g.add_argument('-h', '--help', action='help',
help='show this help message and exit')
g.add_argument('-b', '--breakdown', action='store_true',
help='show a breakdown into individual dice')
g.add_argument('--no-builtins', action='store_true',
help='disable built-in macros')

g = p.add_argument_group('debugging options')
g.add_argument('-v', '--verbose', action = 'store_true',
help = 'enable verbosity')
g.add_argument('--keep-temp-file', action = 'store_true',
help = "don't delete the created temporary file")
g.add_argument('--mock', metavar = 'TYPE', type = int,
help = 'mocking type')
g.add_argument('--mock-const', metavar = 'N', type = int, default = 3,
help = 'mocking constant')
g.add_argument('-v', '--verbose', action='store_true',
help='enable verbosity')
g.add_argument('--keep-temp-file', action='store_true',
help="don't delete the created temporary file")
g.add_argument('--mock', metavar='TYPE', type=int,
help='mocking type')
g.add_argument('--mock-const', metavar='N', type=int, default=3,
help='mocking constant')


a = p.parse_args(args)
a.EXPR = ' '.join(a.EXPR)
return a


def main(EXPR, no_builtins, **kwargs):
"""
The entry point for gnoll when called via `python -m gnoll`
@param EXPR - the expression
@param no_builtins - a flag to disable builtins
@param **kwargs - other key word arguments to be passed to gnoll.roll
"""
_, [[result]], breakdown = gnoll.roll(
EXPR,
builtins = not no_builtins,
Expand All @@ -44,5 +61,6 @@ def main(EXPR, no_builtins, **kwargs):
else:
print(result)


if __name__ == '__main__':
main(**vars(parse_cmdline_args(sys.argv[1:])))

0 comments on commit 884b22c

Please sign in to comment.