-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
43 lines (36 loc) · 1.05 KB
/
cli.py
File metadata and controls
43 lines (36 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from __future__ import annotations
import argparse
import sys
from docxplain.converter import convert_file
from docxplain.formats import get_format, supported_formats
def main() -> None:
"""Command-line entrypoint."""
parser = create_parser()
args = parser.parse_args()
fmt = get_format(args.format)
changed = convert_file(
args.source, output_format=fmt, suffix=args.suffix, header=args.header
)
if changed:
sys.exit(1)
else:
sys.exit(0)
def create_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description="Convert docx to plain text.")
parser.add_argument("source")
parser.add_argument(
"--format",
default="plain",
choices=[f.name for f in supported_formats],
)
parser.add_argument(
"--suffix",
default=None,
help="Custom file suffix for plain text file.",
)
parser.add_argument(
"--header",
default=None,
help="Content to add to the top of the plain text file.",
)
return parser