cli
cli
¶
A command-line front end for the inspection and cleanup operations.
python -m docx answers the questions people ask about a .docx one at a time:
what styles it defines, which are actually used, and why the file is 900 KB. Those are
diagnostic operations — you run them to find out something about a file, not as part of
an application — and a diagnostic API with no command-line front end mostly does not get
used.
Deliberately thin: every subcommand maps onto one public library operation and holds no logic of its own, so the CLI cannot drift from the API or grow behaviour that is only reachable through it. argparse only; no new runtime dependency.
Two rules the commands keep:
- Never modify the input.
cleanupwrites to-oand refuses without it. Someone will point it at their only copy. - Exit codes matter, because this ends up in scripts: non-zero for a document that
cannot be opened, and
--checkreports what would be removed and exits non-zero if anything would be, so it can be a CI gate.
main
¶
Run the CLI; return the process exit code.
argv and stdout are injectable so the tests do not have to drive a subprocess.