Browse files

Updated to python master/1d4a26b38e16dfba858fced505b296743113f3c6

  • Loading branch information...
1 parent c393406 commit cc73221e19a3c000477e6da66c7dbfb7697b980d @shabbyrobe shabbyrobe committed Aug 14, 2012
Showing with 250 additions and 204 deletions.
  1. +19 −11
  2. +227 −192 src/docopt.php
  3. +4 −1 test/testee.php
@@ -11,11 +11,6 @@
> are unlikely to be accepted unless they are themselves direct transliterations
> of bugfixes in the Python version.
-> Though all of the 0.4.2 tests pass, there may still be issues as this port is
-> relatively new. Please visit the
-> [PHP port's issues page](
-> for a list of all current known issues and caveats.
Isn't it awesome how `optparse` and `argparse` generate help messages
based on your code?!
@@ -74,7 +69,7 @@ Installation
"require": {
- "docopt/docopt": "0.4.2"
+ "docopt/docopt": "0.5.0"
@@ -275,17 +270,30 @@ Use the following constructs to specify patterns:
`stdin` is used instead of a file. To support this add "`[-]`" to
you usage patterns. "`-`" act as a normal command.
-If your usage patterns allow to match the same-named argument several times,
-parser will put the matched values into a list, e.g. in case the pattern is
-`my-program.php FILE FILE` then `args['FILE']` will be a list; in case the
-pattern is `my-program.php FILE...` it will also be a list.
+If your pattern allows to match argument-less option (a flag) several times:
+ Usage: [-v | -vv | -vvv]
+then number of occurences of the option will be counted. I.e. `args['-v']`
+will be `2` if program was invoked as `my_program -vv`. Same works for
+If your usage patterns allows to match same-named option with argument
+or positional argument several times, the matched arguments will be
+collected into a list:
+ Usage: <file> <file> --path=<path>...
+I.e. invoked with ` file1 file2 --path=./here --path=./there`
+the returned dict will contain `args['<file>'] == ['file1', 'file2']` and
+`args['--path'] == ['./here', './there']`.
Option descriptions format
**Option descriptions** consist of a list of options that you put below your
-ussage patterns.
+usage patterns.
It is necessary to list option descriptions in order to specify:
Oops, something went wrong. Retry.

3 comments on commit cc73221


Good work!

Wanted to ask you—do you think it was a good design decision to split Pattern class into {Child,Parrent,}Pattern? Do you have any ideas how to refactor the new Pattern class—it knows too much about all its subclasses (in fix* methods and either).


I don't think I'm well placed to comment as I'm not sure how you're planning to refactor docopt to be an NFA. It looks like a good idea to me, but I reckon you've got a better map in your head about how the changes fit in you're head with where you're going with it.

I've got a query though - what problem do the fix* methods solve?


fix_list_arguments (bad name) looks for elements that can occur more than 1 time and sets their value to [] if it's an argument or option with argument, or to 0 if it's a flag or command. So that later values could be collected into a list or their count could be incremented. either method is used only inside this method.

fix_identities makes sure equal elements inside the pattern are the same object. After parsing in case Required(Argument('A'), Argument('A')), the two arguments will be different but equal objects, but after fix_identities() they will be the same object. This way wen you accumulate values into a list (or count values) you operate on the same object.

I'm sure the same effect could be achieved in some other ways and I hope to get rid of those methods somehow.

Please sign in to comment.