2018-05-05 15:04:06 +03:00
|
|
|
"""
|
|
|
|
Parse query arguments.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def parse_args(args):
|
|
|
|
"""
|
|
|
|
Parse arguments and options.
|
|
|
|
Replace short options with their long counterparts.
|
|
|
|
"""
|
2018-05-06 20:35:01 +03:00
|
|
|
result = {
|
|
|
|
'add_comments': True,
|
|
|
|
}
|
2018-05-05 15:04:06 +03:00
|
|
|
|
|
|
|
query = ""
|
|
|
|
for key, val in args.items():
|
|
|
|
if val == "" or val == []:
|
|
|
|
query += key
|
|
|
|
continue
|
|
|
|
|
|
|
|
options_meaning = {
|
2018-05-06 20:35:01 +03:00
|
|
|
"c": dict(add_comments=False, unindent_code=False),
|
|
|
|
"C": dict(add_comments=False, unindent_code=True),
|
2018-05-05 15:04:06 +03:00
|
|
|
"Q": dict(remove_text=True),
|
2018-05-06 20:35:01 +03:00
|
|
|
'q': dict(quiet=True),
|
|
|
|
'T': {'no-terminal': True},
|
2018-05-05 15:04:06 +03:00
|
|
|
}
|
|
|
|
for option, meaning in options_meaning.items():
|
|
|
|
if option in query:
|
|
|
|
result.update(meaning)
|
|
|
|
|
|
|
|
for key, val in args.items():
|
|
|
|
if val == 'True':
|
|
|
|
val = True
|
|
|
|
if val == 'False':
|
|
|
|
val = False
|
|
|
|
result[key] = val
|
|
|
|
|
|
|
|
return result
|