Convert --help and --version to man page or other file types like markdown.
$ help2man --help
usage: help2man [-h] [-V] [--print-completion {bash,zsh,tcsh}] [-n NAME]
[-s SECTION] [-m MANUAL] [-S SOURCE] [-p INFO_PAGE]
[-i INCLUDE] [-o OUTPUT] [--template {man,markdown}]
[--template-file TEMPLATE_FILE] [--help-option HELP_OPTION]
[--version-option VERSION_OPTION] [--no-discard-stderr]
executable ...
Convert --help and --version to man page.
positional arguments:
executable executable program name
... executable program arguments
options:
-h, --help show this help message and exit
-V, --version show program's version number and exit
# ...
$ help2man --version
help2man 0.0.9
Copyright (C) 2022-2023
Written by Wu Zhenyu.help2man help2man | man --local-file -HELP2MAN(1) User Commands HELP2MAN(1)
NAME
help2man - Convert --help and --version to man page.
SYNOPSIS
help2man [-h] [-V] [--print-completion {bash,zsh,tcsh}] [-n NAME]
[-s SECTION] [-m MANUAL] [-S SOURCE] [-p INFO_PAGE]
[-i INCLUDE] [-o OUTPUT] [--template {man,markdown}]
[--template-file TEMPLATE_FILE] [--help-option HELP_OPTION]
[--version-option VERSION_OPTION] [--no-discard-stderr]
executable ...
DESCRIPTION
Convert --help and --version to man page.
POSITIONAL ARGUMENTS
executable
executable program name
... executable program arguments
OPTIONS
-h, --help
show this help message and exit
-V, --version
show program's version number and exit
# ...
AUTHOR
Written by Wu Zhenyu.
REPORTING BUGS
Report bugs to https://github.com/Freed-Wu/help2man/issues .
COPYRIGHT
Copyright © 2022-2023
help2man 0.0.9 2024-11-02 HELP2MAN(1)help2man --template markdown help2man# Man
## Name
help2man - Convert ----help and ----version to man page.
## Synopsis
help2man [-h] [-V] [----print-completion {bash,zsh,tcsh}] [-n NAME]
[-s SECTION] [-m MANUAL] [-S SOURCE] [-p INFO_PAGE]
[-i INCLUDE] [-o OUTPUT] [----template {man,markdown}]
[----template-file TEMPLATE_FILE] [----help-option HELP_OPTION]
[----version-option VERSION_OPTION] [----no-discard-stderr]
executable ...
## Description
Convert ----help and ----version to man page.
## Positional arguments
### executable
executable program name
### ...
executable program arguments
## Options
### -h, ----help
show this help message and exit
### -V, ----version
show program's version number and exit
# ...- GNU help2man Generate manpage for
any program with
--helpand--version. Written in perl. - click-man Generate manpage for click-based python program. Written in python.
- cli2man Generate manpage and
markdown for any program with
--helpand--version. Written in python. - This project: Generate manpage, markdown or any format (if you provide
a jinja template) for
any program with
--helpand--versionor any argparse-based python program.
This a python version of GNU help2man. It solves the following problems1:
Because argparse outputs:
usage: help2man [-h] ...
executable ...
Convert --help and --version to man page.
positional arguments:
executable executable program name
...
options:
-h show this help message and exit
...
help2man will ignore positional arguments: and options: because it only
detect Options:. And it only detect first line as synopsis and detect other
lines as description incorrectly.
I provide help2man --template XXX and help2man --template-file XXX to do
it. The template language is
jinja2. See
template
as examples.
Now you can use it in python. If you want to generate man pages automatically when you build a python project, you can see setuptools-generate:
See document to know more.
Footnotes
-
I send email to the author of
GNU help2manbut got no response. ↩