refactor(CLI): use save function from DocumentConverterResult

This commit is contained in:
abdeladim-s 2024-12-21 13:33:55 -05:00
parent f8e40df008
commit 57ccae421b

View file

@ -57,6 +57,12 @@ def main():
"--output",
help="Output file name. If not provided, output is written to stdout.",
)
parser.add_argument(
"-e",
"--encoding",
help="Encoding of the output file. Defaults to utf-8.",
default="utf-8",
)
args = parser.parse_args()
if args.filename is None:
@ -72,8 +78,7 @@ def main():
def _handle_output(args, result: DocumentConverterResult):
"""Handle output to stdout or file"""
if args.output:
with open(args.output, "w", encoding="utf-8") as f:
f.write(result.text_content)
result.save(args.output, encoding=args.encoding)
else:
print(result.text_content)