refactor(CLI): use save function from DocumentConverterResult
This commit is contained in:
parent
f8e40df008
commit
57ccae421b
1 changed files with 7 additions and 2 deletions
|
|
@ -57,6 +57,12 @@ def main():
|
||||||
"--output",
|
"--output",
|
||||||
help="Output file name. If not provided, output is written to stdout.",
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.filename is None:
|
if args.filename is None:
|
||||||
|
|
@ -72,8 +78,7 @@ def main():
|
||||||
def _handle_output(args, result: DocumentConverterResult):
|
def _handle_output(args, result: DocumentConverterResult):
|
||||||
"""Handle output to stdout or file"""
|
"""Handle output to stdout or file"""
|
||||||
if args.output:
|
if args.output:
|
||||||
with open(args.output, "w", encoding="utf-8") as f:
|
result.save(args.output, encoding=args.encoding)
|
||||||
f.write(result.text_content)
|
|
||||||
else:
|
else:
|
||||||
print(result.text_content)
|
print(result.text_content)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue