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

Support capitalization.

parent 145d70c6
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,14 @@ def handle_options(args):
parser.add_argument(
'-n', '--num', default=6, type=int,
help='number of words to concatenate. Default: 6')
cap_group = parser.add_mutually_exclusive_group()
cap_group.add_argument(
'-c', '--capitalize', action='store_true',
help='Capitalize words. This is the default.')
cap_group.add_argument(
'--no-capitalize', action='store_false', dest='capitalize',
help='Turn off capitalization.')
parser.set_defaults(capiltalize=True)
args = parser.parse_args(args)
return args
......@@ -73,4 +81,5 @@ def main(args=1):
if args is 1:
args = sys.argv[1:]
options = handle_options(args)
print(get_passphrase(wordnum=options.num))
print(get_passphrase(wordnum=options.num,
capitalized=options.capitalize))
......@@ -78,6 +78,16 @@ class TestDicewareModule(object):
r2 = get_passphrase()
assert r1 != r2
def test_get_passphrase_capitals(self):
# by default a passphrase contains upper case chars
phrase = get_passphrase()
assert phrase.lower() != phrase
def test_get_passphrase_no_capitals(self):
# we can turn capitals off
phrase = get_passphrase(capitalized=False)
assert phrase.lower() == phrase
def test_handle_options(self):
# we can get help
with pytest.raises(SystemExit) as exc_info:
......@@ -107,13 +117,15 @@ class TestDicewareModule(object):
out = out.replace(
os.path.basename(sys.argv[0]), 'diceware')
assert out == (
'usage: diceware [-h] [-n NUM]\n'
'usage: diceware [-h] [-n NUM] [-c | --no-capitalize]\n'
'\n'
'Create a passphrase\n'
'\n'
'optional arguments:\n'
' -h, --help show this help message and exit\n'
' -n NUM, --num NUM number of words to concatenate. Default: 6\n'
' -c, --capitalize Capitalize words. This is the default.\n'
' --no-capitalize Turn off capitalization.\n'
)
def test_main_argv(self, argv_handler):
......
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