1
0

testcases.docopt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. r"""Usage: prog
  2. """
  3. $ prog
  4. {}
  5. $ prog --xxx
  6. "user-error"
  7. r"""Usage: prog [options]
  8. Options: -a All.
  9. """
  10. $ prog
  11. {"-a": false}
  12. $ prog -a
  13. {"-a": true}
  14. $ prog -x
  15. "user-error"
  16. r"""Usage: prog [options]
  17. Options: --all All.
  18. """
  19. $ prog
  20. {"--all": false}
  21. $ prog --all
  22. {"--all": true}
  23. $ prog --xxx
  24. "user-error"
  25. r"""Usage: prog [options]
  26. Options: -v, --verbose Verbose.
  27. """
  28. $ prog --verbose
  29. {"--verbose": true}
  30. $ prog --ver
  31. {"--verbose": true}
  32. $ prog -v
  33. {"--verbose": true}
  34. r"""Usage: prog [options]
  35. Options: -p PATH
  36. """
  37. $ prog -p home/
  38. {"-p": "home/"}
  39. $ prog -phome/
  40. {"-p": "home/"}
  41. $ prog -p
  42. "user-error"
  43. r"""Usage: prog [options]
  44. Options: --path <path>
  45. """
  46. $ prog --path home/
  47. {"--path": "home/"}
  48. $ prog --path=home/
  49. {"--path": "home/"}
  50. $ prog --pa home/
  51. {"--path": "home/"}
  52. $ prog --pa=home/
  53. {"--path": "home/"}
  54. $ prog --path
  55. "user-error"
  56. r"""Usage: prog [options]
  57. Options: -p PATH, --path=<path> Path to files.
  58. """
  59. $ prog -proot
  60. {"--path": "root"}
  61. r"""Usage: prog [options]
  62. Options: -p --path PATH Path to files.
  63. """
  64. $ prog -p root
  65. {"--path": "root"}
  66. $ prog --path root
  67. {"--path": "root"}
  68. r"""Usage: prog [options]
  69. Options:
  70. -p PATH Path to files [default: ./]
  71. """
  72. $ prog
  73. {"-p": "./"}
  74. $ prog -phome
  75. {"-p": "home"}
  76. r"""UsAgE: prog [options]
  77. OpTiOnS: --path=<files> Path to files
  78. [dEfAuLt: /root]
  79. """
  80. $ prog
  81. {"--path": "/root"}
  82. $ prog --path=home
  83. {"--path": "home"}
  84. r"""usage: prog [options]
  85. options:
  86. -a Add
  87. -r Remote
  88. -m <msg> Message
  89. """
  90. $ prog -a -r -m Hello
  91. {"-a": true,
  92. "-r": true,
  93. "-m": "Hello"}
  94. $ prog -armyourass
  95. {"-a": true,
  96. "-r": true,
  97. "-m": "yourass"}
  98. $ prog -a -r
  99. {"-a": true,
  100. "-r": true,
  101. "-m": null}
  102. r"""Usage: prog [options]
  103. Options: --version
  104. --verbose
  105. """
  106. $ prog --version
  107. {"--version": true,
  108. "--verbose": false}
  109. $ prog --verbose
  110. {"--version": false,
  111. "--verbose": true}
  112. $ prog --ver
  113. "user-error"
  114. $ prog --verb
  115. {"--version": false,
  116. "--verbose": true}
  117. r"""usage: prog [-a -r -m <msg>]
  118. options:
  119. -a Add
  120. -r Remote
  121. -m <msg> Message
  122. """
  123. $ prog -armyourass
  124. {"-a": true,
  125. "-r": true,
  126. "-m": "yourass"}
  127. r"""usage: prog [-armmsg]
  128. options: -a Add
  129. -r Remote
  130. -m <msg> Message
  131. """
  132. $ prog -a -r -m Hello
  133. {"-a": true,
  134. "-r": true,
  135. "-m": "Hello"}
  136. r"""usage: prog -a -b
  137. options:
  138. -a
  139. -b
  140. """
  141. $ prog -a -b
  142. {"-a": true, "-b": true}
  143. $ prog -b -a
  144. {"-a": true, "-b": true}
  145. $ prog -a
  146. "user-error"
  147. $ prog
  148. "user-error"
  149. r"""usage: prog (-a -b)
  150. options: -a
  151. -b
  152. """
  153. $ prog -a -b
  154. {"-a": true, "-b": true}
  155. $ prog -b -a
  156. {"-a": true, "-b": true}
  157. $ prog -a
  158. "user-error"
  159. $ prog
  160. "user-error"
  161. r"""usage: prog [-a] -b
  162. options: -a
  163. -b
  164. """
  165. $ prog -a -b
  166. {"-a": true, "-b": true}
  167. $ prog -b -a
  168. {"-a": true, "-b": true}
  169. $ prog -a
  170. "user-error"
  171. $ prog -b
  172. {"-a": false, "-b": true}
  173. $ prog
  174. "user-error"
  175. r"""usage: prog [(-a -b)]
  176. options: -a
  177. -b
  178. """
  179. $ prog -a -b
  180. {"-a": true, "-b": true}
  181. $ prog -b -a
  182. {"-a": true, "-b": true}
  183. $ prog -a
  184. "user-error"
  185. $ prog -b
  186. "user-error"
  187. $ prog
  188. {"-a": false, "-b": false}
  189. r"""usage: prog (-a|-b)
  190. options: -a
  191. -b
  192. """
  193. $ prog -a -b
  194. "user-error"
  195. $ prog
  196. "user-error"
  197. $ prog -a
  198. {"-a": true, "-b": false}
  199. $ prog -b
  200. {"-a": false, "-b": true}
  201. r"""usage: prog [ -a | -b ]
  202. options: -a
  203. -b
  204. """
  205. $ prog -a -b
  206. "user-error"
  207. $ prog
  208. {"-a": false, "-b": false}
  209. $ prog -a
  210. {"-a": true, "-b": false}
  211. $ prog -b
  212. {"-a": false, "-b": true}
  213. r"""usage: prog <arg>"""
  214. $ prog 10
  215. {"<arg>": "10"}
  216. $ prog 10 20
  217. "user-error"
  218. $ prog
  219. "user-error"
  220. r"""usage: prog [<arg>]"""
  221. $ prog 10
  222. {"<arg>": "10"}
  223. $ prog 10 20
  224. "user-error"
  225. $ prog
  226. {"<arg>": null}
  227. r"""usage: prog <kind> <name> <type>"""
  228. $ prog 10 20 40
  229. {"<kind>": "10", "<name>": "20", "<type>": "40"}
  230. $ prog 10 20
  231. "user-error"
  232. $ prog
  233. "user-error"
  234. r"""usage: prog <kind> [<name> <type>]"""
  235. $ prog 10 20 40
  236. {"<kind>": "10", "<name>": "20", "<type>": "40"}
  237. $ prog 10 20
  238. {"<kind>": "10", "<name>": "20", "<type>": null}
  239. $ prog
  240. "user-error"
  241. r"""usage: prog [<kind> | <name> <type>]"""
  242. $ prog 10 20 40
  243. "user-error"
  244. $ prog 20 40
  245. {"<kind>": null, "<name>": "20", "<type>": "40"}
  246. $ prog
  247. {"<kind>": null, "<name>": null, "<type>": null}
  248. r"""usage: prog (<kind> --all | <name>)
  249. options:
  250. --all
  251. """
  252. $ prog 10 --all
  253. {"<kind>": "10", "--all": true, "<name>": null}
  254. $ prog 10
  255. {"<kind>": null, "--all": false, "<name>": "10"}
  256. $ prog
  257. "user-error"
  258. r"""usage: prog [<name> <name>]"""
  259. $ prog 10 20
  260. {"<name>": ["10", "20"]}
  261. $ prog 10
  262. {"<name>": ["10"]}
  263. $ prog
  264. {"<name>": []}
  265. r"""usage: prog [(<name> <name>)]"""
  266. $ prog 10 20
  267. {"<name>": ["10", "20"]}
  268. $ prog 10
  269. "user-error"
  270. $ prog
  271. {"<name>": []}
  272. r"""usage: prog NAME..."""
  273. $ prog 10 20
  274. {"NAME": ["10", "20"]}
  275. $ prog 10
  276. {"NAME": ["10"]}
  277. $ prog
  278. "user-error"
  279. r"""usage: prog [NAME]..."""
  280. $ prog 10 20
  281. {"NAME": ["10", "20"]}
  282. $ prog 10
  283. {"NAME": ["10"]}
  284. $ prog
  285. {"NAME": []}
  286. r"""usage: prog [NAME...]"""
  287. $ prog 10 20
  288. {"NAME": ["10", "20"]}
  289. $ prog 10
  290. {"NAME": ["10"]}
  291. $ prog
  292. {"NAME": []}
  293. r"""usage: prog [NAME [NAME ...]]"""
  294. $ prog 10 20
  295. {"NAME": ["10", "20"]}
  296. $ prog 10
  297. {"NAME": ["10"]}
  298. $ prog
  299. {"NAME": []}
  300. r"""usage: prog (NAME | --foo NAME)
  301. options: --foo
  302. """
  303. $ prog 10
  304. {"NAME": "10", "--foo": false}
  305. $ prog --foo 10
  306. {"NAME": "10", "--foo": true}
  307. $ prog --foo=10
  308. "user-error"
  309. r"""usage: prog (NAME | --foo) [--bar | NAME]
  310. options: --foo
  311. options: --bar
  312. """
  313. $ prog 10
  314. {"NAME": ["10"], "--foo": false, "--bar": false}
  315. $ prog 10 20
  316. {"NAME": ["10", "20"], "--foo": false, "--bar": false}
  317. $ prog --foo --bar
  318. {"NAME": [], "--foo": true, "--bar": true}
  319. r"""Naval Fate.
  320. Usage:
  321. prog ship new <name>...
  322. prog ship [<name>] move <x> <y> [--speed=<kn>]
  323. prog ship shoot <x> <y>
  324. prog mine (set|remove) <x> <y> [--moored|--drifting]
  325. prog -h | --help
  326. prog --version
  327. Options:
  328. -h --help Show this screen.
  329. --version Show version.
  330. --speed=<kn> Speed in knots [default: 10].
  331. --moored Mored (anchored) mine.
  332. --drifting Drifting mine.
  333. """
  334. $ prog ship Guardian move 150 300 --speed=20
  335. {"--drifting": false,
  336. "--help": false,
  337. "--moored": false,
  338. "--speed": "20",
  339. "--version": false,
  340. "<name>": ["Guardian"],
  341. "<x>": "150",
  342. "<y>": "300",
  343. "mine": false,
  344. "move": true,
  345. "new": false,
  346. "remove": false,
  347. "set": false,
  348. "ship": true,
  349. "shoot": false}
  350. r"""usage: prog --hello"""
  351. $ prog --hello
  352. {"--hello": true}
  353. r"""usage: prog [--hello=<world>]"""
  354. $ prog
  355. {"--hello": null}
  356. $ prog --hello wrld
  357. {"--hello": "wrld"}
  358. r"""usage: prog [-o]"""
  359. $ prog
  360. {"-o": false}
  361. $ prog -o
  362. {"-o": true}
  363. r"""usage: prog [-opr]"""
  364. $ prog -op
  365. {"-o": true, "-p": true, "-r": false}
  366. r"""usage: prog --aabb | --aa"""
  367. $ prog --aa
  368. {"--aabb": false, "--aa": true}
  369. $ prog --a
  370. "user-error" # not a unique prefix
  371. #
  372. # Counting number of flags
  373. #
  374. r"""Usage: prog -v"""
  375. $ prog -v
  376. {"-v": true}
  377. r"""Usage: prog [-v -v]"""
  378. $ prog
  379. {"-v": 0}
  380. $ prog -v
  381. {"-v": 1}
  382. $ prog -vv
  383. {"-v": 2}
  384. r"""Usage: prog -v ..."""
  385. $ prog
  386. "user-error"
  387. $ prog -v
  388. {"-v": 1}
  389. $ prog -vv
  390. {"-v": 2}
  391. $ prog -vvvvvv
  392. {"-v": 6}
  393. r"""Usage: prog [-v | -vv | -vvv]
  394. This one is probably most readable user-friednly variant.
  395. """
  396. $ prog
  397. {"-v": 0}
  398. $ prog -v
  399. {"-v": 1}
  400. $ prog -vv
  401. {"-v": 2}
  402. $ prog -vvvv
  403. "user-error"
  404. r"""usage: prog [--ver --ver]"""
  405. $ prog --ver --ver
  406. {"--ver": 2}
  407. #
  408. # Counting commands
  409. #
  410. r"""usage: prog [go]"""
  411. $ prog go
  412. {"go": true}
  413. r"""usage: prog [go go]"""
  414. $ prog
  415. {"go": 0}
  416. $ prog go
  417. {"go": 1}
  418. $ prog go go
  419. {"go": 2}
  420. $ prog go go go
  421. "user-error"
  422. r"""usage: prog go..."""
  423. $ prog go go go go go
  424. {"go": 5}
  425. #
  426. # [options] does not include options from usage-pattern
  427. #
  428. r"""usage: prog [options] [-a]
  429. options: -a
  430. -b
  431. """
  432. $ prog -a
  433. {"-a": true, "-b": false}
  434. $ prog -aa
  435. "user-error"
  436. #
  437. # Test [options] shourtcut
  438. #
  439. r"""Usage: prog [options] A
  440. Options:
  441. -q Be quiet
  442. -v Be verbose.
  443. """
  444. $ prog arg
  445. {"A": "arg", "-v": false, "-q": false}
  446. $ prog -v arg
  447. {"A": "arg", "-v": true, "-q": false}
  448. $ prog -q arg
  449. {"A": "arg", "-v": false, "-q": true}
  450. #
  451. # Test single dash
  452. #
  453. r"""usage: prog [-]"""
  454. $ prog -
  455. {"-": true}
  456. $ prog
  457. {"-": false}
  458. #
  459. # If argument is repeated, its value should always be a list
  460. #
  461. r"""usage: prog [NAME [NAME ...]]"""
  462. $ prog a b
  463. {"NAME": ["a", "b"]}
  464. $ prog
  465. {"NAME": []}
  466. #
  467. # Option's argument defaults to null/None
  468. #
  469. r"""usage: prog [options]
  470. options:
  471. -a Add
  472. -m <msg> Message
  473. """
  474. $ prog -a
  475. {"-m": null, "-a": true}
  476. #
  477. # Test options without description
  478. #
  479. r"""usage: prog --hello"""
  480. $ prog --hello
  481. {"--hello": true}
  482. r"""usage: prog [--hello=<world>]"""
  483. $ prog
  484. {"--hello": null}
  485. $ prog --hello wrld
  486. {"--hello": "wrld"}
  487. r"""usage: prog [-o]"""
  488. $ prog
  489. {"-o": false}
  490. $ prog -o
  491. {"-o": true}
  492. r"""usage: prog [-opr]"""
  493. $ prog -op
  494. {"-o": true, "-p": true, "-r": false}
  495. r"""usage: git [-v | --verbose]"""
  496. $ prog -v
  497. {"-v": true, "--verbose": false}
  498. r"""usage: git remote [-v | --verbose]"""
  499. $ prog remote -v
  500. {"remote": true, "-v": true, "--verbose": false}
  501. #
  502. # Test empty usage pattern
  503. #
  504. r"""usage: prog"""
  505. $ prog
  506. {}
  507. r"""usage: prog
  508. prog <a> <b>
  509. """
  510. $ prog 1 2
  511. {"<a>": "1", "<b>": "2"}
  512. $ prog
  513. {"<a>": null, "<b>": null}
  514. r"""usage: prog <a> <b>
  515. prog
  516. """
  517. $ prog
  518. {"<a>": null, "<b>": null}
  519. #
  520. # Option's argument should not capture default value from usage pattern
  521. #
  522. r"""usage: prog [--file=<f>]"""
  523. $ prog
  524. {"--file": null}
  525. r"""usage: prog [--file=<f>]
  526. options: --file <a>
  527. """
  528. $ prog
  529. {"--file": null}
  530. r"""Usage: prog [-a <host:port>]
  531. Options: -a, --address <host:port> TCP address [default: localhost:6283].
  532. """
  533. $ prog
  534. {"--address": "localhost:6283"}
  535. #
  536. # If option with argument could be repeated,
  537. # its arguments should be accumulated into a list
  538. #
  539. r"""usage: prog --long=<arg> ..."""
  540. $ prog --long one
  541. {"--long": ["one"]}
  542. $ prog --long one --long two
  543. {"--long": ["one", "two"]}
  544. #
  545. # Test multiple elements repeated at once
  546. #
  547. r"""usage: prog (go <direction> --speed=<km/h>)..."""
  548. $ prog go left --speed=5 go right --speed=9
  549. {"go": 2, "<direction>": ["left", "right"], "--speed": ["5", "9"]}
  550. #
  551. # Required options should work with option shortcut
  552. #
  553. r"""usage: prog [options] -a
  554. options: -a
  555. """
  556. $ prog -a
  557. {"-a": true}
  558. #
  559. # If option could be repeated its defaults should be split into a list
  560. #
  561. r"""usage: prog [-o <o>]...
  562. options: -o <o> [default: x]
  563. """
  564. $ prog -o this -o that
  565. {"-o": ["this", "that"]}
  566. $ prog
  567. {"-o": ["x"]}
  568. r"""usage: prog [-o <o>]...
  569. options: -o <o> [default: x y]
  570. """
  571. $ prog -o this
  572. {"-o": ["this"]}
  573. $ prog
  574. {"-o": ["x", "y"]}
  575. #
  576. # Test stacked option's argument
  577. #
  578. r"""usage: prog -pPATH
  579. options: -p PATH
  580. """
  581. $ prog -pHOME
  582. {"-p": "HOME"}
  583. #
  584. # Issue 56: Repeated mutually exclusive args give nested lists sometimes
  585. #
  586. r"""Usage: foo (--xx=x|--yy=y)..."""
  587. $ prog --xx=1 --yy=2
  588. {"--xx": ["1"], "--yy": ["2"]}
  589. #
  590. # POSIXly correct tokenization
  591. #
  592. r"""usage: prog [<input file>]"""
  593. $ prog f.txt
  594. {"<input file>": "f.txt"}
  595. r"""usage: prog [--input=<file name>]..."""
  596. $ prog --input a.txt --input=b.txt
  597. {"--input": ["a.txt", "b.txt"]}
  598. #
  599. # Issue 85: `[options]` shourtcut with multiple subcommands
  600. #
  601. r"""usage: prog good [options]
  602. prog fail [options]
  603. options: --loglevel=N
  604. """
  605. $ prog fail --loglevel 5
  606. {"--loglevel": "5", "fail": true, "good": false}
  607. #
  608. # Usage-section syntax
  609. #
  610. r"""usage:prog --foo"""
  611. $ prog --foo
  612. {"--foo": true}
  613. r"""PROGRAM USAGE: prog --foo"""
  614. $ prog --foo
  615. {"--foo": true}
  616. r"""Usage: prog --foo
  617. prog --bar
  618. NOT PART OF SECTION"""
  619. $ prog --foo
  620. {"--foo": true, "--bar": false}
  621. r"""Usage:
  622. prog --foo
  623. prog --bar
  624. NOT PART OF SECTION"""
  625. $ prog --foo
  626. {"--foo": true, "--bar": false}
  627. r"""Usage:
  628. prog --foo
  629. prog --bar
  630. NOT PART OF SECTION"""
  631. $ prog --foo
  632. {"--foo": true, "--bar": false}
  633. #
  634. # Options-section syntax
  635. #
  636. r"""Usage: prog [options]
  637. global options: --foo
  638. local options: --baz
  639. --bar
  640. other options:
  641. --egg
  642. --spam
  643. -not-an-option-
  644. """
  645. $ prog --baz --egg
  646. {"--foo": false, "--baz": true, "--bar": false, "--egg": true, "--spam": false}