-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.py
executable file
·107 lines (94 loc) · 4.85 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
import argparse
import os
from diceware_cli import subcommands
from diceware_cli.persistence import word_states
from os import path
from sys import argv
diceware_dir = path.dirname(path.abspath(__file__))
os.chdir(diceware_dir)
def get_args(cli_args):
parser = argparse.ArgumentParser(prog=path.basename(__file__),
allow_abbrev=False,
)
subparsers = parser.add_subparsers()
subparsers.required = True
subparsers.dest = 'command'
load_db_subparser = subparsers.add_parser('load-db',
help='Load words into the database',
allow_abbrev=False,
)
load_db_subparser.add_argument('-l',
'--language',
help='The language of the wordlist',
type=str,
required=True,
)
load_db_subparser.add_argument('-f',
'--file',
help='A file to load into the db. Use \'-\' for stdin.'
'Repeat this argument for multiple files.',
action='append',
dest='files',
type=argparse.FileType('r'),
required=True,
)
load_db_subparser.add_argument('-s',
'--state',
help='The initial state for the loaded words',
type=str,
default='pending',
choices=word_states,
)
load_db_subparser.add_argument('--allow-updates',
help='Allow words in the DB to have their state updated.'
'Default behavior is insert only.',
dest='allow_updates',
action='store_true',
)
load_db_subparser.set_defaults(func=subcommands.load_db)
clean_subparser = subparsers.add_parser('clean',
help='Clean the project',
allow_abbrev=False,
)
clean_subparser.set_defaults(func=subcommands.clean_project)
finalize_subparser = subparsers.add_parser('finalize',
help='Run checks and generate enumerated wordlists',
allow_abbrev=False,
)
finalize_subparser.set_defaults(func=subcommands.finalize)
select_words_subparser = subparsers.add_parser('select-words',
help='Iterate through the DB and select or reject words',
allow_abbrev=False,
)
select_words_subparser.add_argument('-l',
'--language',
help='The language of the wordlist',
type=str,
required=True,
)
select_words_subparser.add_argument('--include-skipped',
help='Re-evaluated words that were previously skipped',
dest='include_skipped',
action='store_true',
)
select_words_subparser.set_defaults(func=subcommands.select_words)
dump_db_subparser = subparsers.add_parser('dump-db',
help='Dump the contents of the sqlite db to disk',
allow_abbrev=False,
)
dump_db_subparser.set_defaults(func=subcommands.dump_sqlite)
db_state_subparser = subparsers.add_parser('db-state',
help='Get the state of the db',
allow_abbrev=False,
)
db_state_subparser.set_defaults(func=subcommands.db_state)
return parser.parse_args(cli_args)
if __name__ == '__main__':
try:
args = get_args(argv[1:])
args.func(args)
except KeyboardInterrupt:
print('') # for a pretty newline
exit(1)