123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957 |
- r"""Usage: prog
- """
- $ prog
- {}
- $ prog --xxx
- "user-error"
- r"""Usage: prog [options]
- Options: -a All.
- """
- $ prog
- {"-a": false}
- $ prog -a
- {"-a": true}
- $ prog -x
- "user-error"
- r"""Usage: prog [options]
- Options: --all All.
- """
- $ prog
- {"--all": false}
- $ prog --all
- {"--all": true}
- $ prog --xxx
- "user-error"
- r"""Usage: prog [options]
- Options: -v, --verbose Verbose.
- """
- $ prog --verbose
- {"--verbose": true}
- $ prog --ver
- {"--verbose": true}
- $ prog -v
- {"--verbose": true}
- r"""Usage: prog [options]
- Options: -p PATH
- """
- $ prog -p home/
- {"-p": "home/"}
- $ prog -phome/
- {"-p": "home/"}
- $ prog -p
- "user-error"
- r"""Usage: prog [options]
- Options: --path <path>
- """
- $ prog --path home/
- {"--path": "home/"}
- $ prog --path=home/
- {"--path": "home/"}
- $ prog --pa home/
- {"--path": "home/"}
- $ prog --pa=home/
- {"--path": "home/"}
- $ prog --path
- "user-error"
- r"""Usage: prog [options]
- Options: -p PATH, --path=<path> Path to files.
- """
- $ prog -proot
- {"--path": "root"}
- r"""Usage: prog [options]
- Options: -p --path PATH Path to files.
- """
- $ prog -p root
- {"--path": "root"}
- $ prog --path root
- {"--path": "root"}
- r"""Usage: prog [options]
- Options:
- -p PATH Path to files [default: ./]
- """
- $ prog
- {"-p": "./"}
- $ prog -phome
- {"-p": "home"}
- r"""UsAgE: prog [options]
- OpTiOnS: --path=<files> Path to files
- [dEfAuLt: /root]
- """
- $ prog
- {"--path": "/root"}
- $ prog --path=home
- {"--path": "home"}
- r"""usage: prog [options]
- options:
- -a Add
- -r Remote
- -m <msg> Message
- """
- $ prog -a -r -m Hello
- {"-a": true,
- "-r": true,
- "-m": "Hello"}
- $ prog -armyourass
- {"-a": true,
- "-r": true,
- "-m": "yourass"}
- $ prog -a -r
- {"-a": true,
- "-r": true,
- "-m": null}
- r"""Usage: prog [options]
- Options: --version
- --verbose
- """
- $ prog --version
- {"--version": true,
- "--verbose": false}
- $ prog --verbose
- {"--version": false,
- "--verbose": true}
- $ prog --ver
- "user-error"
- $ prog --verb
- {"--version": false,
- "--verbose": true}
- r"""usage: prog [-a -r -m <msg>]
- options:
- -a Add
- -r Remote
- -m <msg> Message
- """
- $ prog -armyourass
- {"-a": true,
- "-r": true,
- "-m": "yourass"}
- r"""usage: prog [-armmsg]
- options: -a Add
- -r Remote
- -m <msg> Message
- """
- $ prog -a -r -m Hello
- {"-a": true,
- "-r": true,
- "-m": "Hello"}
- r"""usage: prog -a -b
- options:
- -a
- -b
- """
- $ prog -a -b
- {"-a": true, "-b": true}
- $ prog -b -a
- {"-a": true, "-b": true}
- $ prog -a
- "user-error"
- $ prog
- "user-error"
- r"""usage: prog (-a -b)
- options: -a
- -b
- """
- $ prog -a -b
- {"-a": true, "-b": true}
- $ prog -b -a
- {"-a": true, "-b": true}
- $ prog -a
- "user-error"
- $ prog
- "user-error"
- r"""usage: prog [-a] -b
- options: -a
- -b
- """
- $ prog -a -b
- {"-a": true, "-b": true}
- $ prog -b -a
- {"-a": true, "-b": true}
- $ prog -a
- "user-error"
- $ prog -b
- {"-a": false, "-b": true}
- $ prog
- "user-error"
- r"""usage: prog [(-a -b)]
- options: -a
- -b
- """
- $ prog -a -b
- {"-a": true, "-b": true}
- $ prog -b -a
- {"-a": true, "-b": true}
- $ prog -a
- "user-error"
- $ prog -b
- "user-error"
- $ prog
- {"-a": false, "-b": false}
- r"""usage: prog (-a|-b)
- options: -a
- -b
- """
- $ prog -a -b
- "user-error"
- $ prog
- "user-error"
- $ prog -a
- {"-a": true, "-b": false}
- $ prog -b
- {"-a": false, "-b": true}
- r"""usage: prog [ -a | -b ]
- options: -a
- -b
- """
- $ prog -a -b
- "user-error"
- $ prog
- {"-a": false, "-b": false}
- $ prog -a
- {"-a": true, "-b": false}
- $ prog -b
- {"-a": false, "-b": true}
- r"""usage: prog <arg>"""
- $ prog 10
- {"<arg>": "10"}
- $ prog 10 20
- "user-error"
- $ prog
- "user-error"
- r"""usage: prog [<arg>]"""
- $ prog 10
- {"<arg>": "10"}
- $ prog 10 20
- "user-error"
- $ prog
- {"<arg>": null}
- r"""usage: prog <kind> <name> <type>"""
- $ prog 10 20 40
- {"<kind>": "10", "<name>": "20", "<type>": "40"}
- $ prog 10 20
- "user-error"
- $ prog
- "user-error"
- r"""usage: prog <kind> [<name> <type>]"""
- $ prog 10 20 40
- {"<kind>": "10", "<name>": "20", "<type>": "40"}
- $ prog 10 20
- {"<kind>": "10", "<name>": "20", "<type>": null}
- $ prog
- "user-error"
- r"""usage: prog [<kind> | <name> <type>]"""
- $ prog 10 20 40
- "user-error"
- $ prog 20 40
- {"<kind>": null, "<name>": "20", "<type>": "40"}
- $ prog
- {"<kind>": null, "<name>": null, "<type>": null}
- r"""usage: prog (<kind> --all | <name>)
- options:
- --all
- """
- $ prog 10 --all
- {"<kind>": "10", "--all": true, "<name>": null}
- $ prog 10
- {"<kind>": null, "--all": false, "<name>": "10"}
- $ prog
- "user-error"
- r"""usage: prog [<name> <name>]"""
- $ prog 10 20
- {"<name>": ["10", "20"]}
- $ prog 10
- {"<name>": ["10"]}
- $ prog
- {"<name>": []}
- r"""usage: prog [(<name> <name>)]"""
- $ prog 10 20
- {"<name>": ["10", "20"]}
- $ prog 10
- "user-error"
- $ prog
- {"<name>": []}
- r"""usage: prog NAME..."""
- $ prog 10 20
- {"NAME": ["10", "20"]}
- $ prog 10
- {"NAME": ["10"]}
- $ prog
- "user-error"
- r"""usage: prog [NAME]..."""
- $ prog 10 20
- {"NAME": ["10", "20"]}
- $ prog 10
- {"NAME": ["10"]}
- $ prog
- {"NAME": []}
- r"""usage: prog [NAME...]"""
- $ prog 10 20
- {"NAME": ["10", "20"]}
- $ prog 10
- {"NAME": ["10"]}
- $ prog
- {"NAME": []}
- r"""usage: prog [NAME [NAME ...]]"""
- $ prog 10 20
- {"NAME": ["10", "20"]}
- $ prog 10
- {"NAME": ["10"]}
- $ prog
- {"NAME": []}
- r"""usage: prog (NAME | --foo NAME)
- options: --foo
- """
- $ prog 10
- {"NAME": "10", "--foo": false}
- $ prog --foo 10
- {"NAME": "10", "--foo": true}
- $ prog --foo=10
- "user-error"
- r"""usage: prog (NAME | --foo) [--bar | NAME]
- options: --foo
- options: --bar
- """
- $ prog 10
- {"NAME": ["10"], "--foo": false, "--bar": false}
- $ prog 10 20
- {"NAME": ["10", "20"], "--foo": false, "--bar": false}
- $ prog --foo --bar
- {"NAME": [], "--foo": true, "--bar": true}
- r"""Naval Fate.
- Usage:
- prog ship new <name>...
- prog ship [<name>] move <x> <y> [--speed=<kn>]
- prog ship shoot <x> <y>
- prog mine (set|remove) <x> <y> [--moored|--drifting]
- prog -h | --help
- prog --version
- Options:
- -h --help Show this screen.
- --version Show version.
- --speed=<kn> Speed in knots [default: 10].
- --moored Mored (anchored) mine.
- --drifting Drifting mine.
- """
- $ prog ship Guardian move 150 300 --speed=20
- {"--drifting": false,
- "--help": false,
- "--moored": false,
- "--speed": "20",
- "--version": false,
- "<name>": ["Guardian"],
- "<x>": "150",
- "<y>": "300",
- "mine": false,
- "move": true,
- "new": false,
- "remove": false,
- "set": false,
- "ship": true,
- "shoot": false}
- r"""usage: prog --hello"""
- $ prog --hello
- {"--hello": true}
- r"""usage: prog [--hello=<world>]"""
- $ prog
- {"--hello": null}
- $ prog --hello wrld
- {"--hello": "wrld"}
- r"""usage: prog [-o]"""
- $ prog
- {"-o": false}
- $ prog -o
- {"-o": true}
- r"""usage: prog [-opr]"""
- $ prog -op
- {"-o": true, "-p": true, "-r": false}
- r"""usage: prog --aabb | --aa"""
- $ prog --aa
- {"--aabb": false, "--aa": true}
- $ prog --a
- "user-error" # not a unique prefix
- #
- # Counting number of flags
- #
- r"""Usage: prog -v"""
- $ prog -v
- {"-v": true}
- r"""Usage: prog [-v -v]"""
- $ prog
- {"-v": 0}
- $ prog -v
- {"-v": 1}
- $ prog -vv
- {"-v": 2}
- r"""Usage: prog -v ..."""
- $ prog
- "user-error"
- $ prog -v
- {"-v": 1}
- $ prog -vv
- {"-v": 2}
- $ prog -vvvvvv
- {"-v": 6}
- r"""Usage: prog [-v | -vv | -vvv]
- This one is probably most readable user-friednly variant.
- """
- $ prog
- {"-v": 0}
- $ prog -v
- {"-v": 1}
- $ prog -vv
- {"-v": 2}
- $ prog -vvvv
- "user-error"
- r"""usage: prog [--ver --ver]"""
- $ prog --ver --ver
- {"--ver": 2}
- #
- # Counting commands
- #
- r"""usage: prog [go]"""
- $ prog go
- {"go": true}
- r"""usage: prog [go go]"""
- $ prog
- {"go": 0}
- $ prog go
- {"go": 1}
- $ prog go go
- {"go": 2}
- $ prog go go go
- "user-error"
- r"""usage: prog go..."""
- $ prog go go go go go
- {"go": 5}
- #
- # [options] does not include options from usage-pattern
- #
- r"""usage: prog [options] [-a]
- options: -a
- -b
- """
- $ prog -a
- {"-a": true, "-b": false}
- $ prog -aa
- "user-error"
- #
- # Test [options] shourtcut
- #
- r"""Usage: prog [options] A
- Options:
- -q Be quiet
- -v Be verbose.
- """
- $ prog arg
- {"A": "arg", "-v": false, "-q": false}
- $ prog -v arg
- {"A": "arg", "-v": true, "-q": false}
- $ prog -q arg
- {"A": "arg", "-v": false, "-q": true}
- #
- # Test single dash
- #
- r"""usage: prog [-]"""
- $ prog -
- {"-": true}
- $ prog
- {"-": false}
- #
- # If argument is repeated, its value should always be a list
- #
- r"""usage: prog [NAME [NAME ...]]"""
- $ prog a b
- {"NAME": ["a", "b"]}
- $ prog
- {"NAME": []}
- #
- # Option's argument defaults to null/None
- #
- r"""usage: prog [options]
- options:
- -a Add
- -m <msg> Message
- """
- $ prog -a
- {"-m": null, "-a": true}
- #
- # Test options without description
- #
- r"""usage: prog --hello"""
- $ prog --hello
- {"--hello": true}
- r"""usage: prog [--hello=<world>]"""
- $ prog
- {"--hello": null}
- $ prog --hello wrld
- {"--hello": "wrld"}
- r"""usage: prog [-o]"""
- $ prog
- {"-o": false}
- $ prog -o
- {"-o": true}
- r"""usage: prog [-opr]"""
- $ prog -op
- {"-o": true, "-p": true, "-r": false}
- r"""usage: git [-v | --verbose]"""
- $ prog -v
- {"-v": true, "--verbose": false}
- r"""usage: git remote [-v | --verbose]"""
- $ prog remote -v
- {"remote": true, "-v": true, "--verbose": false}
- #
- # Test empty usage pattern
- #
- r"""usage: prog"""
- $ prog
- {}
- r"""usage: prog
- prog <a> <b>
- """
- $ prog 1 2
- {"<a>": "1", "<b>": "2"}
- $ prog
- {"<a>": null, "<b>": null}
- r"""usage: prog <a> <b>
- prog
- """
- $ prog
- {"<a>": null, "<b>": null}
- #
- # Option's argument should not capture default value from usage pattern
- #
- r"""usage: prog [--file=<f>]"""
- $ prog
- {"--file": null}
- r"""usage: prog [--file=<f>]
- options: --file <a>
- """
- $ prog
- {"--file": null}
- r"""Usage: prog [-a <host:port>]
- Options: -a, --address <host:port> TCP address [default: localhost:6283].
- """
- $ prog
- {"--address": "localhost:6283"}
- #
- # If option with argument could be repeated,
- # its arguments should be accumulated into a list
- #
- r"""usage: prog --long=<arg> ..."""
- $ prog --long one
- {"--long": ["one"]}
- $ prog --long one --long two
- {"--long": ["one", "two"]}
- #
- # Test multiple elements repeated at once
- #
- r"""usage: prog (go <direction> --speed=<km/h>)..."""
- $ prog go left --speed=5 go right --speed=9
- {"go": 2, "<direction>": ["left", "right"], "--speed": ["5", "9"]}
- #
- # Required options should work with option shortcut
- #
- r"""usage: prog [options] -a
- options: -a
- """
- $ prog -a
- {"-a": true}
- #
- # If option could be repeated its defaults should be split into a list
- #
- r"""usage: prog [-o <o>]...
- options: -o <o> [default: x]
- """
- $ prog -o this -o that
- {"-o": ["this", "that"]}
- $ prog
- {"-o": ["x"]}
- r"""usage: prog [-o <o>]...
- options: -o <o> [default: x y]
- """
- $ prog -o this
- {"-o": ["this"]}
- $ prog
- {"-o": ["x", "y"]}
- #
- # Test stacked option's argument
- #
- r"""usage: prog -pPATH
- options: -p PATH
- """
- $ prog -pHOME
- {"-p": "HOME"}
- #
- # Issue 56: Repeated mutually exclusive args give nested lists sometimes
- #
- r"""Usage: foo (--xx=x|--yy=y)..."""
- $ prog --xx=1 --yy=2
- {"--xx": ["1"], "--yy": ["2"]}
- #
- # POSIXly correct tokenization
- #
- r"""usage: prog [<input file>]"""
- $ prog f.txt
- {"<input file>": "f.txt"}
- r"""usage: prog [--input=<file name>]..."""
- $ prog --input a.txt --input=b.txt
- {"--input": ["a.txt", "b.txt"]}
- #
- # Issue 85: `[options]` shourtcut with multiple subcommands
- #
- r"""usage: prog good [options]
- prog fail [options]
- options: --loglevel=N
- """
- $ prog fail --loglevel 5
- {"--loglevel": "5", "fail": true, "good": false}
- #
- # Usage-section syntax
- #
- r"""usage:prog --foo"""
- $ prog --foo
- {"--foo": true}
- r"""PROGRAM USAGE: prog --foo"""
- $ prog --foo
- {"--foo": true}
- r"""Usage: prog --foo
- prog --bar
- NOT PART OF SECTION"""
- $ prog --foo
- {"--foo": true, "--bar": false}
- r"""Usage:
- prog --foo
- prog --bar
- NOT PART OF SECTION"""
- $ prog --foo
- {"--foo": true, "--bar": false}
- r"""Usage:
- prog --foo
- prog --bar
- NOT PART OF SECTION"""
- $ prog --foo
- {"--foo": true, "--bar": false}
- #
- # Options-section syntax
- #
- r"""Usage: prog [options]
- global options: --foo
- local options: --baz
- --bar
- other options:
- --egg
- --spam
- -not-an-option-
- """
- $ prog --baz --egg
- {"--foo": false, "--baz": true, "--bar": false, "--egg": true, "--spam": false}
|