Added a simple CLI.
This commit is contained in:
@@ -49,6 +49,9 @@ Source = "https://github.com/microsoft/markitdown"
|
|||||||
[tool.hatch.version]
|
[tool.hatch.version]
|
||||||
path = "src/markitdown/__about__.py"
|
path = "src/markitdown/__about__.py"
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
markitdown = "markitdown.__main__:main"
|
||||||
|
|
||||||
[tool.hatch.envs.types]
|
[tool.hatch.envs.types]
|
||||||
extra-dependencies = [
|
extra-dependencies = [
|
||||||
"mypy>=1.0.0",
|
"mypy>=1.0.0",
|
||||||
|
|||||||
42
src/markitdown/__main__.py
Normal file
42
src/markitdown/__main__.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# SPDX-FileCopyrightText: 2024-present Adam Fourney <adamfo@microsoft.com>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
import sys
|
||||||
|
from ._markitdown import MarkItDown
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if len(sys.argv) == 1:
|
||||||
|
markitdown = MarkItDown()
|
||||||
|
result = markitdown.convert_stream(sys.stdin.buffer)
|
||||||
|
print(result.text_content)
|
||||||
|
elif len(sys.argv) == 2:
|
||||||
|
markitdown = MarkItDown()
|
||||||
|
result = markitdown.convert(sys.argv[1])
|
||||||
|
print(result.text_content)
|
||||||
|
else:
|
||||||
|
sys.stderr.write(
|
||||||
|
"""
|
||||||
|
SYNTAX:
|
||||||
|
|
||||||
|
markitdown <OPTIONAL: FILENAME>
|
||||||
|
If FILENAME is empty, markitdown reads from stdin.
|
||||||
|
|
||||||
|
EXAMPLE:
|
||||||
|
|
||||||
|
markitdown example.pdf
|
||||||
|
|
||||||
|
OR
|
||||||
|
|
||||||
|
cat example.pdf | markitdown
|
||||||
|
|
||||||
|
OR
|
||||||
|
|
||||||
|
markitdown < example.pdf
|
||||||
|
""".strip()
|
||||||
|
+ "\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user