|
| 1 | +import argparse |
| 2 | +import logging |
1 | 3 | import os |
2 | 4 |
|
3 | 5 | from dotenv import load_dotenv |
| 6 | +from rich.console import Console |
| 7 | +from rich.logging import RichHandler |
| 8 | +from rich_argparse import RichHelpFormatter |
4 | 9 |
|
5 | 10 | load_dotenv() |
6 | 11 |
|
|
15 | 20 | "host": os.getenv("POSTGRES_HOST"), |
16 | 21 | "port": os.getenv("5432"), |
17 | 22 | } |
| 23 | + |
| 24 | + |
| 25 | +logging.basicConfig(level="INFO", format="%(message)s", handlers=[RichHandler()]) |
| 26 | +logger = logging.getLogger(__name__) |
| 27 | + |
| 28 | +console = Console() |
| 29 | + |
| 30 | + |
| 31 | +class CustomFormatter(RichHelpFormatter): |
| 32 | + styles = { |
| 33 | + "argparse.prog": "bold cyan", |
| 34 | + "argparse.args": "cyan", |
| 35 | + "argparse.metavar": "yellow", |
| 36 | + "argparse.help": "white", |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | +def parse_args(): |
| 41 | + parser = argparse.ArgumentParser( |
| 42 | + prog="coord_buffer_cli", |
| 43 | + description="Creates a specified buffer around user specified area.", |
| 44 | + epilog="Ex: uv run coord_buffer_cli --msid 3982 -b 5", |
| 45 | + formatter_class=CustomFormatter, |
| 46 | + ) |
| 47 | + source_group = parser.add_mutually_exclusive_group(required=True) |
| 48 | + |
| 49 | + source_group.add_argument( |
| 50 | + "-l", |
| 51 | + "--list", |
| 52 | + action="store_true", |
| 53 | + help="Prints list of available geometries and their id.", |
| 54 | + ) |
| 55 | + |
| 56 | + source_group.add_argument( |
| 57 | + "--msid", |
| 58 | + type=int, |
| 59 | + help="Fetch coordinates for the given MSID.", |
| 60 | + ) |
| 61 | + |
| 62 | + source_group.add_argument( |
| 63 | + "-f", |
| 64 | + "--input_file", |
| 65 | + help="Path to a GeoJSON file.", |
| 66 | + ) |
| 67 | + parser.add_argument( |
| 68 | + "-b", "--buffer", type=float, default=0.0, help="Buffer size in nautical miles." |
| 69 | + ) |
| 70 | + return parser.parse_args() |
0 commit comments