From 868331d51e26cd07ed6f5c009a2b55b3109e5038 Mon Sep 17 00:00:00 2001 From: nicolas-schreiber <34018356+nicolas-schreiber@users.noreply.github.com> Date: Mon, 25 Jul 2022 10:48:49 +0200 Subject: [PATCH] Added overwrite option to cli, for simpler automation (#9) * Added overwrite option to cli, for simpler automation * Fix the cli documentation comments * Updated the doc message for overwrite --- README.md | 1 + obj2mjcf/_cli.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 86b2379..ed46458 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ optional arguments: --save-mjcf save an example XML (MJCF) file --compile-model compile the MJCF file to check for errors --verbose print verbose output + --overwrite overwrite previous run output optional vhacd_args arguments: arguments to pass to V-HACD diff --git a/obj2mjcf/_cli.py b/obj2mjcf/_cli.py index 1976eef..c4e153c 100644 --- a/obj2mjcf/_cli.py +++ b/obj2mjcf/_cli.py @@ -102,6 +102,8 @@ class Args: vhacd_args: VhacdArgs = field(default_factory=VhacdArgs) """arguments to pass to V-HACD""" texture_args: TextureArgs = field(default_factory=TextureArgs) + overwrite: bool = False + """overwrite previous run output""" @dataclass @@ -249,12 +251,13 @@ def process_obj(filename: Path, args: Args) -> None: # and materials will be stored there. work_dir = filename.parent / filename.stem if work_dir.exists(): - proceed = input( - f"{work_dir.resolve()} already exists, maybe from a previous run? " - "Proceeding will overwrite it.\nDo you wish to continue [y/n]: " - ) - if proceed.lower() != "y": - return + if not args.overwrite: + proceed = input( + f"{work_dir.resolve()} already exists, maybe from a previous run? " + "Proceeding will overwrite it.\nDo you wish to continue [y/n]: " + ) + if proceed.lower() != "y": + return shutil.rmtree(work_dir) work_dir.mkdir(exist_ok=True) logging.info(f"Saving processed meshes to {work_dir}")