Parse arguments and options. Replace short options with their long counterparts.
(args)
| 4 | |
| 5 | |
| 6 | def parse_args(args): |
| 7 | """ |
| 8 | Parse arguments and options. |
| 9 | Replace short options with their long counterparts. |
| 10 | """ |
| 11 | result = { |
| 12 | "add_comments": True, |
| 13 | } |
| 14 | |
| 15 | query = "" |
| 16 | newargs = {} |
| 17 | for key, val in args.items(): |
| 18 | if val == "" or val == [] or val == [""]: |
| 19 | query += key |
| 20 | continue |
| 21 | if val == "True": |
| 22 | val = True |
| 23 | if val == "False": |
| 24 | val = False |
| 25 | newargs[key] = val |
| 26 | |
| 27 | options_meaning = { |
| 28 | "c": dict(add_comments=False, unindent_code=False), |
| 29 | "C": dict(add_comments=False, unindent_code=True), |
| 30 | "Q": dict(remove_text=True), |
| 31 | "q": dict(quiet=True), |
| 32 | "T": {"no-terminal": True}, |
| 33 | } |
| 34 | for option, meaning in options_meaning.items(): |
| 35 | if option in query: |
| 36 | result.update(meaning) |
| 37 | |
| 38 | result.update(newargs) |
| 39 | |
| 40 | return result |