From 1085925af08a91d13d33dff509e674cb90dfb277 Mon Sep 17 00:00:00 2001 From: lumin Date: Fri, 20 Dec 2024 23:13:43 +0900 Subject: [PATCH] feat: add version option to markitdown CLI Add a `--version` option to the markitdown command-line interface that displays the current version number. --- src/markitdown/__main__.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/markitdown/__main__.py b/src/markitdown/__main__.py index be2a0f2..a41b7e4 100644 --- a/src/markitdown/__main__.py +++ b/src/markitdown/__main__.py @@ -1,38 +1,49 @@ # SPDX-FileCopyrightText: 2024-present Adam Fourney # # SPDX-License-Identifier: MIT -import sys import argparse +import sys from textwrap import dedent + +from .__about__ import __version__ from ._markitdown import MarkItDown def main(): parser = argparse.ArgumentParser( description="Convert various file formats to markdown.", + prog="markitdown", formatter_class=argparse.RawDescriptionHelpFormatter, usage=dedent( """ - SYNTAX: - + SYNTAX: + markitdown If FILENAME is empty, markitdown reads from stdin. - + EXAMPLE: - + markitdown example.pdf - + OR - + cat example.pdf | markitdown - - OR - + + OR + markitdown < example.pdf """ ).strip(), ) + parser.add_argument( + "-v", + "--version", + action="version", + version=f"%(prog)s {__version__}", + help="show the version number and exit", + ) + parser.add_argument("filename", nargs="?") args = parser.parse_args()