Skip to content

Commit f31df4a

Browse files
committed
Updated API docs to be composer compatible
1 parent c10f9e1 commit f31df4a

1 file changed

Lines changed: 35 additions & 30 deletions

File tree

README.rst

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ and instead can write only the help message--*the way you want it*.
7373
DOC;
7474
7575
require('path/to/src/docopt.php');
76-
$args = Docopt\docopt($doc, array('version'=>'Naval Fate 2.0'));
76+
$handler = new \Docopt\Handler(array('version'=>'Naval Fate 2.0'));
77+
$args = $handler->handle($doc);
7778
foreach ($args as $k=>$v)
7879
echo $k.': '.json_encode($v).PHP_EOL;
7980
@@ -120,8 +121,8 @@ API
120121
<?php
121122
require('/path/to/src/docopt.php');
122123
123-
// short form
124-
$args = Docopt\docopt($sdoc);
124+
// short form (5.4 or better)
125+
$args = (new \Docopt\Handler)->handle($sdoc);
125126
126127
// long form (equivalent to short)
127128
$params = array(
@@ -130,32 +131,14 @@ API
130131
'version'=>null,
131132
'optionsFirst'=>false,
132133
);
133-
$args = Docopt\docopt($doc, $params);
134+
$handler = new \Docopt\Handler($params);
135+
$args = $handler->handle($doc);
134136
135137
136-
``docopt`` takes 1 required and 1 optional argument:
138+
The constructor for ``Docopt\Handler`` takes one optional argument (the
139+
defaults are listed in the above example):
137140

138-
- ``doc`` is a string that contains a **help message** that will be parsed to
139-
create the option parser. The simple rules of how to write such a
140-
help message are given in next sections. Here is a quick example of
141-
such a string:
142-
143-
.. code:: php
144-
145-
<?php
146-
$doc = <<<DOC
147-
Usage: my_program.php [-hso FILE] [--quiet | --verbose] [INPUT ...]
148-
149-
-h --help show this
150-
-s --sorted sorted output
151-
-o FILE specify output file [default: ./test.txt]
152-
--quiet print less text
153-
--verbose print more text
154-
155-
DOC;
156-
157-
158-
- ``params`` is an optional array of additional data to influence
141+
- ``params`` is an array of additional data to influence
159142
``docopt``. The following keys are supported:
160143

161144
- ``argv`` is an optional argument vector; by default ``docopt`` uses
@@ -189,10 +172,32 @@ API
189172
compatibility with POSIX, or if you want to dispatch your arguments
190173
to other programs.
191174

192-
The **return** value is a simple associative array with options, arguments
193-
and commands as keys, spelled exactly like in your help message. Long
194-
versions of options are given priority. For example, if you invoke the
195-
top example as::
175+
``Docopt\Handler->handle()`` takes one required argument:
176+
177+
- ``doc`` is a string that contains a **help message** that will be parsed to
178+
create the option parser. The simple rules of how to write such a
179+
help message are given in next sections. Here is a quick example of
180+
such a string:
181+
182+
.. code:: php
183+
184+
<?php
185+
$doc = <<<DOC
186+
Usage: my_program.php [-hso FILE] [--quiet | --verbose] [INPUT ...]
187+
188+
-h --help show this
189+
-s --sorted sorted output
190+
-o FILE specify output file [default: ./test.txt]
191+
--quiet print less text
192+
--verbose print more text
193+
194+
DOC;
195+
196+
197+
The **return** value of ``handle()`` is a simple associative array with
198+
options, arguments and commands as keys, spelled exactly like in your
199+
help message. Long versions of options are given priority. For example,
200+
if you invoke the top example as::
196201
197202
naval_fate.php ship Guardian move 100 150 --speed=15
198203

0 commit comments

Comments
 (0)