Skip to content

Commit

Permalink
fix: abort if output-dir is not a dir (#7478)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifer-richards committed May 28, 2024
1 parent 39d471d commit 1cdfd97
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ietf/bin/aliases-from-json.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ def generate_files(records, adest, vdest, postconfirm, vdomain):
shutil.move(vpath, vdest)


def directory_path(val):
p = Path(val)
if p.is_dir():
return p
else:
raise argparse.ArgumentTypeError(f"{p} is not a directory")

if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Convert a JSON stream of draft alias definitions into alias / virtual alias files."
Expand All @@ -73,7 +80,7 @@ def generate_files(records, adest, vdest, postconfirm, vdomain):
parser.add_argument(
"--output-dir",
default="./",
type=Path,
type=directory_path,
help="Destination for output files.",
)
parser.add_argument(
Expand All @@ -87,8 +94,6 @@ def generate_files(records, adest, vdest, postconfirm, vdomain):
help=f"Virtual domain (defaults to {VDOMAIN}_",
)
args = parser.parse_args()
if not args.output_dir.is_dir():
sys.stderr.write("Error: output-dir must be a directory")
data = json.load(sys.stdin)
generate_files(
data["aliases"],
Expand Down

0 comments on commit 1cdfd97

Please sign in to comment.