diff --git a/pokeapi_ditto/commands/analyze.py b/pokeapi_ditto/commands/analyze.py index 9bcbeebe6..daa590984 100644 --- a/pokeapi_ditto/commands/analyze.py +++ b/pokeapi_ditto/commands/analyze.py @@ -10,7 +10,7 @@ from pokeapi_ditto.common import from_dir -def do_analyze(api_dir: str, schema_dir: str): +def do_analyze(api_dir: str, schema_dir: str, log: bool): if not Path(schema_dir).exists(): Path(schema_dir).mkdir(parents=True) @@ -38,7 +38,8 @@ def gen_single_schema(path: Path) -> SchemaBuilder: @from_dir(schema_dir) def gen_schemas(paths: List[Path]): for path in paths: - print(Path(schema_dir).joinpath(path)) + if log: + print(Path(schema_dir).joinpath(path)) if not path.parent.exists(): os.makedirs(path.parent) schema = gen_single_schema(path) diff --git a/pokeapi_ditto/commands/clone.py b/pokeapi_ditto/commands/clone.py index ce009d3b6..6ede56f46 100644 --- a/pokeapi_ditto/commands/clone.py +++ b/pokeapi_ditto/commands/clone.py @@ -7,7 +7,7 @@ from pokeapi_ditto.common import BASE_URL_PLACEHOLDER -def do_clone(src_url, dest_dir): +def do_clone(src_url: str, dest_dir: str, log: bool): if not src_url.endswith("/"): src_url += "/" @@ -29,7 +29,8 @@ def print_json(data, file_name): endpoints = requests.get(url) path = dest_dir + url.replace(src_url, "") + "index.json" - print(path) + if log: + print(path) print_json(endpoints.json(), path) # Endpoints @@ -44,7 +45,8 @@ def print_json(data, file_name): url = endpoint + "?limit=" + count resource_list = requests.get(url) path = dest_dir + endpoint.replace(src_url, "") + "index.json" - print(path) + if log: + print(path) print_json(resource_list.json(), path) # All resources diff --git a/pokeapi_ditto/commands/transform.py b/pokeapi_ditto/commands/transform.py index bfc13071f..49724a62f 100644 --- a/pokeapi_ditto/commands/transform.py +++ b/pokeapi_ditto/commands/transform.py @@ -4,7 +4,7 @@ from pokeapi_ditto.common import apply_base_url -def do_transform(src_dir: str, dest_dir: str, base_url: str): +def do_transform(src_dir: str, dest_dir: str, base_url: str, log: bool): src_dir: Path = Path(src_dir) dest_dir: Path = Path(dest_dir) @@ -18,7 +18,8 @@ def do_transform(src_dir: str, dest_dir: str, base_url: str): for orig in orig_paths: new = dest_dir.joinpath(orig.relative_to(src_dir)) - print(new) + if log: + print(new) if not new.parent.exists(): new.parent.mkdir(parents=True) diff --git a/pokeapi_ditto/main.py b/pokeapi_ditto/main.py index f4f3d0f55..d21d0bb6a 100644 --- a/pokeapi_ditto/main.py +++ b/pokeapi_ditto/main.py @@ -3,12 +3,21 @@ from gevent.pywsgi import WSGIServer +from pokeapi_ditto import __version__ from pokeapi_ditto.commands import analyze, clone, serve, transform class Ditto(object): def __init__(self): parser = argparse.ArgumentParser() + parser.add_argument("--version", action="version", version=__version__) + parser.add_argument( + "--log", + action="store_const", + const=True, + default=False, + help="turn on logging of files saved", + ) subparsers = parser.add_subparsers(dest="command") clone_args = subparsers.add_parser("clone")