diff --git a/src/markitdown/__main__.py b/src/markitdown/__main__.py index b6cf963..ba0240a 100644 --- a/src/markitdown/__main__.py +++ b/src/markitdown/__main__.py @@ -13,36 +13,14 @@ def main(): description="Convert various file formats to markdown.", prog="markitdown", formatter_class=argparse.RawDescriptionHelpFormatter, - usage=dedent( - """ - SYNTAX: - - markitdown - If FILENAME is empty, markitdown reads from stdin. - - EXAMPLE: - - markitdown example.pdf - - OR - - cat example.pdf | markitdown - - OR - - markitdown < example.pdf - - OR to save to a file use - - markitdown example.pdf -o example.md - - OR - - markitdown example.pdf > example.md - """ - ).strip(), + epilog=dedent( + """\ + examples: + markitdown example.pdf + markitdown -o example.md example.pdf + cat example.pdf | markitdown > example.md""" + ), ) - parser.add_argument( "-v", "--version", @@ -50,30 +28,27 @@ def main(): version=f"%(prog)s {__version__}", help="show the version number and exit", ) - - parser.add_argument("filename", nargs="?") + parser.add_argument( + "filename", nargs="?", help="if unspecified, defaults to stdin" + ) parser.add_argument( "-o", "--output", - help="Output file name. If not provided, output is written to stdout.", + dest="filename", + help="if unspecified, defaults to stdout", ) + args = parser.parse_args() + markitdown = MarkItDown() if args.filename is None: - markitdown = MarkItDown() result = markitdown.convert_stream(sys.stdin.buffer) - _handle_output(args, result) else: - markitdown = MarkItDown() result = markitdown.convert(args.filename) - _handle_output(args, result) - -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) + print(result.text_content, file=f) else: print(result.text_content)