Home Page

Tips page

University Page

Programming

Debian & Linux

Some works

About me

Del.icio.us Bookmarks

BOINC Combined Statistics

Site Statistics

Contact me sending an e-mail (antispam defense activated)

debian

hacker emblem

blogger

GeoURL

View Sandro Tosi's profile on LinkedIn

This is my Google PageRank

Generate a skel for manpage from "prog --help"

Generate a skel for manpage from "prog --help"

 Sandro Tosi, 04 August 2006


In my role as Debian packages maintainer, I have to provide a good package, and this could mean to write a manpage if the upstream author does not provide one.

It's common to have a tool that invoked with -h or --help switch generates a list of its options with their meaning.

The following script takes the output of "prog --help" and generate a skeleton for options part of a manpage (anymeal is the program I was packaging while writing this script):

anymeal --help-all | grep "^  -" | sed 's/  -/.TP \ .B -/' | sed 's| --| \\-\\-|g' | sed 's| -| \\-|g'

note the space in the grep command and in the substitution part for sed: adjust for the output.

Here is chunk of the output of anymeal --help-all:

--help                    Show help about options
--help-qt                 Show Qt specific options
--help-kde                Show KDE specific options
--help-all                Show all options
--author                  Show author information
-v, --version             Show version information
--license                 Show license information

and the trasformation applyied by the script:

.TP
.B \-\-help                    Show help about options
.TP
.B \-\-help-qt                 Show Qt specific options
.TP
.B \-\-help-kde                Show KDE specific options
.TP
.B \-\-help-all                Show all options
.TP
.B \-\-author                  Show author information
.TP
.B \-v, \-\-version             Show version information
.TP
.B \-\-license                 Show license information

now, you are only left to take the description in the row below ".B ..." and you've done.

If you have installed the package man-db, you can find some examples of man pages in the directory /usr/share/doc/man-db/examples/.

On 2006-08-19 I've discovered the tool help2man, that does almost the same thing...