Skip to content

Commit

Permalink
cli: fixed directory conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
juk0de committed Jul 13, 2024
1 parent 3bb5bef commit 9453547
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions mtf2json/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,29 @@ def main() -> None:
args.convert = True

# convert given MTF file(s)
for i, mtf_file in enumerate(args.mtf_file):
path = Path(mtf_file)
if not path.exists():
print(f"File {path} does not exist!")
sys.exit(1)
try:
data = read_mtf(path)
except ConversionError as e:
print(f"Failed to convert '{path}': {e}")
sys.exit(1)

# convert to JSON and print or write to file
if args.convert:
json_path = Path(args.json_file[i]) if args.json_file else path.with_suffix('.json')
if args.mtf_file:
for i, mtf_file in enumerate(args.mtf_file):
path = Path(mtf_file)
if not path.exists():
print(f"File {path} does not exist!")
sys.exit(1)
try:
write_json(data, json_path)
print(f"Successfully saved JSON file '{json_path}'.")
except Exception as e:
print(f"Error: writing '{json_path}' failed with '{e}'")
data = read_mtf(path)
except ConversionError as e:
print(f"Failed to convert '{path}': {e}")
sys.exit(1)
else:
print(json.dumps(data))

# convert to JSON and print or write to file
if args.convert:
json_path = Path(args.json_file[i]) if args.json_file else path.with_suffix('.json')
try:
write_json(data, json_path)
print(f"Successfully saved JSON file '{json_path}'.")
except Exception as e:
print(f"Error: writing '{json_path}' failed with '{e}'")
sys.exit(1)
else:
print(json.dumps(data))

# convert all MTF files in given directory
if args.mtf_dir:
Expand Down

0 comments on commit 9453547

Please sign in to comment.