This is also used by `brew <cmd> --help`. The basic idea is to have the
documentation as a top level comment in each command file. To find these
comments, they have to be like this `#:`.
This is also used by the `brew man` command to keep the documentation
DRY, and for that there are now a header and footer for the man page.
Also use `popen_read` instead of `safe_system` for cleaner argument
passing and write the output with `atomic_write`.
ClosesHomebrew/homebrew#46826.
Signed-off-by: Martin Afanasjew <martin@afanasjew.de>