Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Short Option Details

Short Flag Merging

When multiple short options are boolean flags, they can be combined into a single - token.

command.add_argument(Argument("all",       help="Show all").long["all"]().short["a"]().flag())
command.add_argument(Argument("brief",     help="Brief mode").long["brief"]().short["b"]().flag())
command.add_argument(Argument("colorize",  help="Colorize").long["colorize"]().short["c"]().flag())
myapp -abc
# Expands to: -a -b -c
# all = True, brief = True, colorize = True

Mixing flags with a value-taking option: The last character in a merged group can take a value (the rest of the token or the next argument):

command.add_argument(Argument("output", help="Output file").long["output"]().short["o"]())
myapp -abofile.txt
# Expands to: -a -b -o file.txt
# all = True, brief = True, output = "file.txt"

Attached Short Values

A short option that takes a value can have its value attached directly — no space needed.

command.add_argument(Argument("output", help="Output file").long["output"]().short["o"]())
myapp -ofile.txt          # output = "file.txt"
myapp -o file.txt         # output = "file.txt"  (same result)

This is the same behaviour as GCC’s -O2, tar’s -xzf archive.tar.gz, and similar UNIX traditions.