Skip to content
Snippets Groups Projects
Commit de26eb59 authored by ulif's avatar ulif
Browse files

Support num argument.

parent 6fe18e9b
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,9 @@ def handle_options(args): ...@@ -19,6 +19,9 @@ def handle_options(args):
"""Handle commandline options. """Handle commandline options.
""" """
parser = argparse.ArgumentParser(description="Create a passphrase") parser = argparse.ArgumentParser(description="Create a passphrase")
parser.add_argument(
'-n', '--num', default=6, type=int,
help='number of words to concatenate. Default: 6')
args = parser.parse_args(args) args = parser.parse_args(args)
return args return args
......
...@@ -62,6 +62,11 @@ class TestDicewareModule(object): ...@@ -62,6 +62,11 @@ class TestDicewareModule(object):
handle_options(['--help']) handle_options(['--help'])
assert exc_info.value.code == 0 assert exc_info.value.code == 0
def test_handle_options_defaults(self):
# defaults are correctly set
options = handle_options([])
assert options.num == 6
def test_main(self, capsys): def test_main(self, capsys):
# we can get help # we can get help
with pytest.raises(SystemExit) as exc_info: with pytest.raises(SystemExit) as exc_info:
...@@ -71,10 +76,11 @@ class TestDicewareModule(object): ...@@ -71,10 +76,11 @@ class TestDicewareModule(object):
out = out.replace( out = out.replace(
os.path.basename(sys.argv[0]), 'diceware') os.path.basename(sys.argv[0]), 'diceware')
assert out == ( assert out == (
'usage: diceware [-h]\n' 'usage: diceware [-h] [-n NUM]\n'
'\n' '\n'
'Create a passphrase\n' 'Create a passphrase\n'
'\n' '\n'
'optional arguments:\n' 'optional arguments:\n'
' -h, --help show this help message and exit\n' ' -h, --help show this help message and exit\n'
' -n NUM, --num NUM number of words to concatenate. Default: 6\n'
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment