init
This commit is contained in:
43
docx_thesis/cli.py
Normal file
43
docx_thesis/cli.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""CLI entry point for the thesis converter (used by `uv run thesis`)."""
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from .config import ThesisFormat
|
||||
from .converter import ThesisConverter
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="将 Markdown 毕业论文转换为格式化的 Word 文档",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog=(
|
||||
"示例:\n"
|
||||
" uv run thesis 论文.md # 输出 论文.docx\n"
|
||||
" uv run thesis 论文.md 毕业设计.docx # 指定输出文件名\n"
|
||||
),
|
||||
)
|
||||
parser.add_argument("input", help="输入的 .md 文件路径")
|
||||
parser.add_argument("output", nargs="?", default=None,
|
||||
help="输出的 .docx 路径(默认自动替换扩展名)")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
inp = Path(args.input)
|
||||
if not inp.exists():
|
||||
print(f"错误:找不到文件 {inp}")
|
||||
sys.exit(1)
|
||||
|
||||
out = Path(args.output) if args.output else inp.with_suffix(".docx")
|
||||
|
||||
config = ThesisFormat()
|
||||
converter = ThesisConverter(config)
|
||||
converter.convert(str(inp), str(out))
|
||||
|
||||
print(f"转换完成:{out}")
|
||||
print("提示:在 Word 中打开后,按 Ctrl+A → F9 更新目录和页码。")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user