Accept values from arguments
This commit is contained in:
parent
81ac7e94fa
commit
09113a4777
1 changed files with 10 additions and 5 deletions
|
@ -6,13 +6,11 @@ from pathlib import Path
|
|||
from typing import TypedDict
|
||||
from collections import defaultdict
|
||||
from urllib.request import urlopen
|
||||
import argparse
|
||||
import json
|
||||
|
||||
TRAEFIK_HOST_RE = re.compile(r"Host\(`([a-z0-9\.-]+)`\)")
|
||||
|
||||
CONFIG_FILE = Path.cwd() / "config.toml"
|
||||
OUTPUT_FILE = Path.cwd() / "map.txt"
|
||||
|
||||
|
||||
class Route(NamedTuple):
|
||||
name: str
|
||||
|
@ -79,7 +77,14 @@ def get_dokku_routes(dokku_exporter_url: str, dokku_route: str):
|
|||
|
||||
|
||||
def main():
|
||||
config: Config = tomllib.loads(CONFIG_FILE.read_text())
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument("--config", "-c", default="./config.toml", type=Path, help="Config file. Default: %(default)s")
|
||||
parser.add_argument("--output", "-o", type=Path, default="./map.txt", help="Output file. Default: %(default)s")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
config: Config = tomllib.loads(args.config.read_text())
|
||||
|
||||
routes = []
|
||||
for source in config["source"]:
|
||||
|
@ -96,7 +101,7 @@ def main():
|
|||
for route in routes:
|
||||
grouped_routes[route.hostname, route.destination].add(route.name)
|
||||
|
||||
with OUTPUT_FILE.open("w", buffering=1024 * 1024) as f:
|
||||
with args.output.open("w", buffering=1024 * 1024) as f:
|
||||
for (hostname, destination), names in sorted(grouped_routes.items()):
|
||||
print(f"{hostname}\t{destination}; # {', '.join(names)}", file=f)
|
||||
|
||||
|
|
Reference in a new issue