diff --git a/diceware.py b/diceware.py index 1346462ff6f14aeb045c559588eb49564523325f..81cc318bbe5e4b164927c5fcdb5f46df381b2a4c 100644 --- a/diceware.py +++ b/diceware.py @@ -35,6 +35,11 @@ def handle_options(args): parser.add_argument( '-s', '--specials', default=0, type=int, metavar='NUM', help="Insert NUM special chars into generated word.") + parser.add_argument( + 'infile', nargs='?', metavar='INFILE', default=None, + type=argparse.FileType('r'), + help="Input wordlist", + ) parser.set_defaults(capitalize=True) args = parser.parse_args(args) return args diff --git a/tests/test_diceware.py b/tests/test_diceware.py index c0b783c548fd1d52ba37c4f3408d4a910b3fddae..cbd25f7341a60efa60ef623d7945dbce9e366ecf 100644 --- a/tests/test_diceware.py +++ b/tests/test_diceware.py @@ -138,6 +138,15 @@ class TestDicewareModule(object): assert options.num == 6 assert options.capitalize is True assert options.specials == 0 + assert options.infile is None + + def test_handle_options_infile(self): + # we can give an infile + with open('mywords', 'w') as fd: + fd.write('one\ntwo\n') + options = handle_options(['mywords',]) + assert options.infile is not None + assert options.infile.read() == 'one\ntwo\n' def test_main(self, capsys): # we can get a passphrase @@ -157,10 +166,13 @@ class TestDicewareModule(object): out = out.replace( os.path.basename(sys.argv[0]), 'diceware') assert out == ( - 'usage: diceware [-h] [-n NUM] [-c | --no-caps] [-s NUM]\n' + 'usage: diceware [-h] [-n NUM] [-c | --no-caps] [-s NUM] [INFILE]\n' '\n' 'Create a passphrase\n' '\n' + 'positional arguments:\n' + ' INFILE Input wordlist\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'