1 | # lognestmonster Copyright (c) 2019 Joshua 'joshuas3' Stockin |
2 | # <https://github.com/JoshuaS3/lognestmonster/>. |
3 |
|
4 |
|
5 | # This file is part of lognestmonster. |
6 |
|
7 | # lognestmonster is free software: you can redistribute it and/or modify |
8 | # it under the terms of the GNU General Public License as published by |
9 | # the Free Software Foundation, either version 3 of the License, or |
10 | # (at your option) any later version. |
11 |
|
12 | # lognestmonster is distributed in the hope that it will be useful, |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | # GNU General Public License for more details. |
16 |
|
17 | # You should have received a copy of the GNU General Public License |
18 | # along with lognestmonster. If not, see <https://www.gnu.org/licenses/>. |
19 |
|
20 | from format import * |
21 | from args import * |
22 | # yeah, I know argparse is a thing, but I don't like it... |
23 |
|
24 | def get_arg_from_indicator(indicator): |
25 | for option in ARGUMENT_OPTIONS: |
26 | if indicator in ARGUMENT_OPTIONS[option]["indicators"]: |
27 | return option |
28 | return None |
29 |
|
30 | def get_arg_description(name): |
31 | return ARGUMENT_OPTIONS[name]["description"] |
32 |
|
33 | def parseargs(argv): |
34 | options = {} |
35 | argn = 0 |
36 | while argn < len(argv): |
37 | arg = argv[argn] |
38 | if arg == "-": |
39 | argn += 1 |
40 | continue |
41 | opt = get_arg_from_indicator(arg) |
42 | if arg.startswith("-") and opt is None: # is a flag/option but is not known |
43 | options = TEXT_RED + "error:" + RESET + " unknown flag/option '" + arg + "'" |
44 | break |
45 | options[opt] = None |
46 | argn += 1 |
47 | return options |
48 |
|