Create Beautiful Python Command-line Interface (POSIX C Fashion)

Create Beautiful Python Command-line Interface (POSIX C Fashion)

Summary

PyCon UK 2012: Create beautiful command-line interfaces with Python

github autobackup

Command-line Interface Standard
IEEE Std 1003.1 / POSIX

Some Option/Arugement Parser Library for Python

  1. optparse
  2. argparse
  3. docopt (Recommended)

Differences Between Argument, Option and Command

Argument (常规参数)

Angular Bracket ()

1
<argument> ARGUMENT

Option (可选参数)

Start with dash(-)
Option Argument (UPPERCASE)

1
2
3
-o, --option
-f FILE
--select=ERROR

Command (命令)

some example (一些案例)

1
2
3
4
5
6
my_program ship new <name>
my_program ship <name> move <x> <y> [--speed=<kn>]
my_program ship shoot <x> <y>
my_program mine (set|remove) <x> <y> [--mored|--drifing]
my_program -h | --help
my_program --version

其他

1
2
"|" pipe, vertical bar
"..." ellipsis