[Docpie]

Fork me on GitHub

Options Format


Options defines several options which can be used in your [options] "Usage" shortcut.

Options section starts with "Options:" (case-insensitive), ends with a visibly empty line or the end of the help message. In "Options" you can define

  • the synonymous of a option,
  • the description of a option, and
  • whether a option expects argument and it's default value.

Define Synonymous & Argument

Different synonymous option should be separated an optional comma, and one space.

-h, -?, --help    # with comma
-v --version      # without comma

Use one space to separate the option and the argument. For long option, =(equal) is recommanded. argument follows the same rules of "Argument" in "Usage".

-r <file> --read <file>     # without `=`
-w FILE --write=FILE        # with`=`

Write Description

For inline description, use at least 2 spaces to separate the options. For newline description, indent 2 more spaces for each line.

-l --logging             open the logging.             # Good. Inline description
-r <file> --read <file>  read the data from the file.  # Good, 2 spaces
                         if the file does not exists, create one. 
                         # Good, keep the indent
-w FILE --write=FILE
        write the data to the file  # Good, new line indent 2 more spaces
        create one if not exists    # Good, keep the indent
        raise RuntimeError if fails to create
        raise IOError if fails to write

Define Default Value

For options that accept argument(s), you can specify a default value. To do so, first write [default:, and a space), followed by your default value, and ends with ]. The whole block looks like [default: <your-default-value>]. Put this block to the end of your description.

--speed=<km/h>    the speed of the ship.[default: inf]    # 'inf'
--ship=<name>     the name of the ship
                  create one if not exist. [default: ]    # an empty string

If you like this project, you can buy me a beer to help me make it better! | Flattr this

侧栏导航