Penz
Penz

Reputation: 5628

Command line format description language

Many man pages and --help option use a format for describing the command line options of the documented utilities. For instance, for the cd shell command:

cd [-L | -P] [directory]
cd -

I'd like to parse these descriptions. Is there a model or formal format (even if it is not widely accepted)?

I've seen that at least python's argparse (http://pymotw.com/2/argparse/) can generate something like that.

Upvotes: 1

Views: 124

Answers (1)

manlio
manlio

Reputation: 18902

Some details about the notation used for the SYNOPSIS section can be found in the man manual:

The following conventions apply to the SYNOPSIS section and can be used as a guide in other sections.

 bold text          type exactly as shown.
 italic text        replace with appropriate argument.
 [-abc]             any or all arguments within [ ] are optional.
 -a|-b              options delimited by | cannot be used together.

 argument ...       argument is repeatable.
 [expression] ...   entire expression within [ ] is repeatable.

Exact rendering may vary depending on the output device. For instance, man will usually not be able to render italics when running in a terminal, and will typically use underlined or coloured text instead.

The command or function illustration is a pattern that should match all possible invocations. In some cases it is advisable to illustrate several exclusive invocations as is shown in the SYNOPSIS section of this manual page.

There are further details in the the POSIX Utility Syntax Guidelines.

Many libraries to parse the command line options can generate the synopsis section (e.g. take a look at boost::program_options).

Upvotes: 1

Related Questions