Coerce --dump-agent-logs from str to bool, woops
#!/usr/bin/env python3
+import argparse
import logging
import os
import sys
@@ -9,6 +10,7 @@ from typing import Any, Optional
# Odd path is due to the `/etc` root pattern in pants.toml, fyi
from ci_scripts.dump_artifacts import docker_artifacts, nomad_artifacts
+from grapl_common.utils.primitive_convertors import to_bool
# need minimum 3.7 for capture_output=True
assert sys.version_info >= (
@@ -21,9 +23,8 @@ LOGGER.setLevel(logging.INFO)
LOGGER.addHandler(logging.StreamHandler(stream=sys.stdout))
-def parse_args() -> Any:
- import argparse
-
+class Args:
+ def __init__(self) -> None:
parser = argparse.ArgumentParser(
description="Dump all Docker logs for a given docker-compose project"
)
@@ -39,15 +40,17 @@ def parse_args() -> Any:
dest="dump_agent_logs",
required=False,
default=False,
- help="Dump the logs for Nomad/Consul agents (e.g. running locally)",
+ help="Dump the logs for Nomad/Consul agents (e.g. running locally). [True / False]",
)
- return parser.parse_args()
+ args = parser.parse_args()
+ self.compose_project: Optional[str] = args.compose_project
+ # coerce from str -> Optional[bool] -> bool
+ self.dump_agent_logs = bool(to_bool(args.dump_agent_logs))
def main() -> None:
- args = parse_args()
- compose_project: Optional[str] = args.compose_project
- dump_agent_logs: bool = args.dump_agent_logs
+ args = Args()
+ compose_project = args.compose_project
cwd = os.getcwd()
timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
@@ -69,7 +72,7 @@ def main() -> None:
compose_project=None, volume_name="dynamodb_dump", artifacts_dir=artifacts_dir
)
- nomad_artifacts.dump_all(artifacts_dir, dump_agent_logs=dump_agent_logs)
+ nomad_artifacts.dump_all(artifacts_dir, dump_agent_logs=args.dump_agent_logs)
LOGGER.info(f"Dumped to {artifacts_dir}")
