@@ -9,40 +9,21 @@ efficient.
99
1010As a result, unless a bug is present only in the PHP version, pull requests
1111are unlikely to be accepted unless they are themselves direct transliterations
12- of bugfixes in the Python version.
12+ of bugfixes in the Python version.
1313
14+ New in version 0.6.1:
15+
16+ - API has changed slightly. ``Docopt\docopt `` has been renamed to ``Docopt::handle ``
17+ to fix autoloader support. See issue #3.
1418
15- Video introduction to **docopt **: `PyCon UK 2012: Create *beautiful*
16- command-line interfaces with Python <http://youtu.be/pXhcPJK5cMc> `_
17-
18- New in version 0.6.1:
19-
20- - Fix issue `#85 <https://github.com/docopt/docopt/issues/85 >`_
21- which caused improper handling of ``[options] `` shortcut
22- if it was present several times.
23-
24- New in version 0.6.0:
25-
26- - New argument ``options_first ``, disallows interspersing options
27- and arguments. If you supply ``options_first=True `` to
28- ``docopt ``, it will interpret all arguments as positional
29- arguments after first positional argument.
19+ - Compatibility with Python master branch at commit `d5b96f878a <https://github.com/docopt/docopt/commit/d5b96f878abbda51b62f1e28010d2b42b19a27dc >`_
3020
31- - If option with argument could be repeated, its default value
32- will be interpreted as space-separated list. E.g. with
33- ``[default: ./here ./there] `` will be interpreted as
34- ``['./here', './there'] ``.
21+ - Potentially serious BC break in `issue 102 <https://github.com/docopt/docopt/issues/102 >`_
3522
36- Breaking changes:
23+ Please see the `Python version's README <https://github.com/docopt/docopt/blob/master/README.rst >`_
24+ for any new and breaking changes that are not specific to the PHP version.
3725
38- - Meaning of ``[options] `` shortcut slightly changed. Previously
39- it meant *"any known option" *. Now it means *"any option not in
40- usage-pattern" *. This avoids the situation when an option is
41- allowed to be repeated unintentionally.
42-
43- - ``argv `` is ``None `` by default, not ``sys.argv[1:] ``.
44- This allows ``docopt `` to always use the *latest * ``sys.argv ``,
45- not ``sys.argv `` during import time.
26+ -----
4627
4728Isn't it awesome how ``optparse `` and ``argparse `` generate help
4829messages based on your code?!
@@ -79,7 +60,7 @@ and instead can write only the help message--*the way you want it*.
7960 DOC;
8061
8162 require('path/to/src/docopt.php');
82- $args = Docopt\docopt ($doc, array('version'=>'Naval Fate 2.0'));
63+ $args = Docopt::handle ($doc, array('version'=>'Naval Fate 2.0'));
8364 foreach ($args as $k=>$v)
8465 echo $k.': '.json_encode($v).PHP_EOL;
8566
@@ -103,7 +84,7 @@ Create a ``composer.json`` file for your project
10384
10485 {
10586 " require" : {
106- " docopt/docopt" : " >=0.6.1 "
87+ " docopt/docopt" : " >=0.6.* "
10788 }
10889 }
10990
@@ -112,10 +93,10 @@ Install using composer::
11293 php composer.phar install
11394
11495
115- Alternatively, you can just drop `docopt.php ` file into your project--it is
96+ Alternatively, you can just drop `` docopt.php ` ` file into your project--it is
11697self-contained. `Get source on github <http://github.com/docopt/docopt.php >`_.
11798
118- ``docopt.php `` is tested with PHP 5.3
99+ ``docopt.php `` is tested with PHP 5.4 and PHP 5.3.
119100
120101
121102API
@@ -126,20 +107,27 @@ API
126107 <?php
127108 require('/path/to/src/docopt.php');
128109
129- // short form
130- $args = Docopt\ docopt($sdoc );
110+ // short form, simple API
111+ $args = Docopt:: docopt($doc );
131112
132- // long form (equivalent to short)
113+ // long form, simple API (equivalent to short)
133114 $params = array(
134115 'argv'=>array_slice($_SERVER['argv'], 1),
135116 'help'=>true,
136117 'version'=>null,
137118 'optionsFirst'=>false,
138119 );
139- $args = Docopt\docopt($doc, $params);
120+ $args = Docopt::docopt($doc, $params);
121+
122+ // long form, full API
123+ $handler = new \Docopt\Handler(array(
124+ 'help'=>true,
125+ 'optionsFirst'=>false,
126+ ));
127+ $handler->handle($doc, $argv);
140128
141129
142- ``docopt `` takes 1 required and 1 optional argument:
130+ ``Docopt::handle() `` takes 1 required and 1 optional argument:
143131
144132- ``doc `` is a string that contains a **help message ** that will be parsed to
145133 create the option parser. The simple rules of how to write such a
@@ -151,12 +139,13 @@ API
151139 <?php
152140 $doc = <<<DOC
153141 Usage: my_program.php [-hso FILE] [--quiet | --verbose] [INPUT ...]
154-
155- -h --help show this
156- -s --sorted sorted output
157- -o FILE specify output file [default: . /test.txt]
158- --quiet print less text
159- --verbose print more text
142+
143+ Options:
144+ -h --help show this
145+ -s --sorted sorted output
146+ -o FILE specify output file [default: . /test.txt]
147+ --quiet print less text
148+ --verbose print more text
160149
161150 DOC;
162151
@@ -222,23 +211,25 @@ the return dictionary will be:
222211 Help message format
223212======================================================================
224213
225- Help message consists of 2 parts :
214+ Help message consists of 2 sections :
226215
227- - Usage pattern, e.g.::
216+ - Usage section, starting with `` Usage: `` e.g.::
228217
229218 Usage: my_program.php [-hso FILE] [--quiet | --verbose] [INPUT ...]
230219
231- - Option descriptions, e.g.::
220+ - Option section, starting with `` Options: `` e.g.::
232221
233- -h --help show this
234- -s --sorted sorted output
235- -o FILE specify output file [default: ./test.txt]
236- --quiet print less text
237- --verbose print more text
222+ Options:
223+ -h --help show this
224+ -s --sorted sorted output
225+ -o FILE specify output file [default: ./test.txt]
226+ --quiet print less text
227+ --verbose print more text
238228
239229Their format is described below; other text is ignored.
240230
241- Usage pattern format
231+
232+ Usage section format
242233----------------------------------------------------------------------
243234
244235**Usage pattern ** is a substring of ``doc `` that starts with
@@ -265,7 +256,7 @@ Each pattern can consist of the following elements:
265256 options, e.g. ``-oiv `` which will be the same as ``-o -i -v ``. The
266257 options can have arguments, e.g. ``--input=FILE `` or ``-i FILE `` or
267258 even ``-iFILE ``. However it is important that you specify option
268- descriptions if you want for option to have an argument, a default
259+ descriptions if you want your option to have an argument, a default
269260 value, or specify synonymous short/long versions of option (see next
270261 section on option descriptions).
271262- **commands ** are words that do *not * follow the described above
@@ -389,6 +380,7 @@ The rules are as follows:
389380 # will be './here ./there', because it is not repeatable
390381 --not-repeatable=<arg> [default: ./here ./there]
391382
383+
392384Examples
393385----------------------------------------------------------------------
394386
@@ -397,6 +389,7 @@ We have an extensive list of `examples
397389every aspect of functionality of **docopt **. Try them out, read the
398390source if in doubt.
399391
392+
400393Subparsers, multi-level help and *huge * applications (like git)
401394----------------------------------------------------------------------
402395
0 commit comments