Skip to content

Commit 1cdfd97

Browse files
fix: abort if output-dir is not a dir (ietf-tools#7478)
1 parent 39d471d commit 1cdfd97

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

ietf/bin/aliases-from-json.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ def generate_files(records, adest, vdest, postconfirm, vdomain):
6161
shutil.move(vpath, vdest)
6262

6363

64+
def directory_path(val):
65+
p = Path(val)
66+
if p.is_dir():
67+
return p
68+
else:
69+
raise argparse.ArgumentTypeError(f"{p} is not a directory")
70+
6471
if __name__ == "__main__":
6572
parser = argparse.ArgumentParser(
6673
description="Convert a JSON stream of draft alias definitions into alias / virtual alias files."
@@ -73,7 +80,7 @@ def generate_files(records, adest, vdest, postconfirm, vdomain):
7380
parser.add_argument(
7481
"--output-dir",
7582
default="./",
76-
type=Path,
83+
type=directory_path,
7784
help="Destination for output files.",
7885
)
7986
parser.add_argument(
@@ -87,8 +94,6 @@ def generate_files(records, adest, vdest, postconfirm, vdomain):
8794
help=f"Virtual domain (defaults to {VDOMAIN}_",
8895
)
8996
args = parser.parse_args()
90-
if not args.output_dir.is_dir():
91-
sys.stderr.write("Error: output-dir must be a directory")
9297
data = json.load(sys.stdin)
9398
generate_files(
9499
data["aliases"],

0 commit comments

Comments
 (0)