Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Freed-Wu/help2man

Repository files navigation

help2man

pre-commit.ci status github/workflow codecov readthedocs

github/downloads github/downloads/latest github/issues github/issues-closed github/issues-pr github/issues-pr-closed github/discussions github/milestones github/forks github/stars github/watchers github/contributors github/commit-activity github/last-commit github/release-date

github/license github/languages github/languages/top github/directory-file-count github/code-size github/repo-size github/v

pypi/status pypi/v pypi/downloads pypi/format pypi/implementation pypi/pyversions

Convert --help and --version to man page or other file types like markdown.

Usage

$ 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.

Man

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)

Markdown

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

# ...

Similar Projects

  • GNU help2man Generate manpage for any program with --help and --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 --help and --version. Written in python.
  • This project: Generate manpage, markdown or any format (if you provide a jinja template) for any program with --help and --version or any argparse-based python program.

Intention

This a python version of GNU help2man. It solves the following problems1:

GNU help2man cannot convert argparse correctly

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.

GNU help2man cannot customize template

I provide help2man --template XXX and help2man --template-file XXX to do it. The template language is jinja2. See template as examples.

GNU help2man don't provide any programming API

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

  1. I send email to the author of GNU help2man but got no response.