MetarNavigate/src/metar_navigate/application.py

66 lines
2.4 KiB
Python

import argparse
import sys
import rich
from metar_navigate.utils import ConfigManager
class Application:
def __init__(self):
self.parser = None
self.args = None
self.config = ConfigManager()
def setup(self):
self._validate_args()
if self.config.read_config() is None:
rich.print("[bold red]No config file found. Please run metarNavigate --configure[/bold red] ")
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("--configure", "-c" ,action="store_true", help="runs the configuration wizard")
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.configure and self.args.ICAO:
self.parser.error("--configure não aceita código ICAO")
if self.args.configure and self.args.detailed:
self.parser.error("--configure não pode ser usado com --detailed")
if self.args.configure and ('--type' in sys.argv or '-t' in sys.argv):
self.parser.error("--configure não pode ser usado com --type/-t")
if self.args.no_tui and not self.args.configure and not self.args.ICAO:
self.parser.error("--no-tui requer código ICAO (exceto quando usado com --configure)")
if self.args.ICAO and not self.args.no_tui:
self.parser.error("Código ICAO só pode ser usado com --no-tui")
if self.args.detailed and not self.args.no_tui:
self.parser.error("--detailed requer --no-tui")
if not self.args.no_tui and ('--type' in sys.argv or '-t' in sys.argv):
self.parser.error("--type/-t requer --no-tui")
def run(self):
pass