import argparse import sys from metar_navigate.ui import RichInterface from metar_navigate.utils import ConfigManager class Application: def __init__(self): self.parser = None self.args = None self.config = ConfigManager() self.ui = None self.is_configured = False def setup(self) -> None: if self.config.read_config() is not None: self.is_configured = True self._validate_args() if self.args.no_tui: self.ui = RichInterface(self) if self.args.configure: self.ui.setup(configure=True) if self.args.detailed: self.ui.setup(detailed=True) 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): self.ui.run()