Add argument parsing to `Application` class and integrate setup in entry point
This commit is contained in:
parent
7a75126708
commit
fac9a70548
|
|
@ -1,7 +1,35 @@
|
|||
import argparse
|
||||
import sys
|
||||
|
||||
|
||||
class Application:
|
||||
def __init__(self):
|
||||
pass
|
||||
self.parser = None
|
||||
self.args = None
|
||||
|
||||
def setup(self):
|
||||
self._validate_args()
|
||||
|
||||
def _validate_args(self):
|
||||
self.parser = argparse.ArgumentParser()
|
||||
self.parser.add_argument("--no-tui", action="store_true", help="disables the TUI")
|
||||
self.parser.add_argument("--detailed", action="store_true", help="displays more detailed METAR Breakdown "
|
||||
"(Only available with --no-tui flag)")
|
||||
self.parser.add_argument("-t", "--type", choices=["TAF", "METAR"], default="METAR", help="Select the Type "
|
||||
"of message (Only Available with"
|
||||
" --no-tui flag)")
|
||||
self.parser.add_argument("ICAO", nargs='?', type=str.upper,help="ICAO code of airport (required with --no-tui flag)")
|
||||
|
||||
self.args = self.parser.parse_args()
|
||||
|
||||
if self.args.no_tui and not self.args.ICAO:
|
||||
self.parser.error("--no-tui requires an ICAO code")
|
||||
if self.args.ICAO and not self.args.no_tui:
|
||||
self.parser.error("ICAO code only required with --no-tui flag")
|
||||
if not self.args.no_tui and self.args.detailed:
|
||||
self.parser.error("--detailed flag only available with --no-tui flag")
|
||||
if not self.args.no_tui and ('--type' in sys.argv or '-t' in sys.argv):
|
||||
self.parser.error("--type or -t flag only available with --no-tui flag")
|
||||
|
||||
def run(self):
|
||||
pass
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -2,4 +2,5 @@ from metar_navigate import Application
|
|||
|
||||
def main():
|
||||
app = Application()
|
||||
print("Hello World")
|
||||
app.setup()
|
||||
app.run()
|
||||
Loading…
Reference in New Issue