Download the PHP package docopt/docopt without Composer

On this page you can find all versions of the php package docopt/docopt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package docopt

docopt creates beautiful command-line interfaces

This is a straight PHP transliteration of Vladimir Keleshev's brilliant docopt Python library. There are a few artefacts in the code as a result that may seem inefficient and non-idiomatic to PHP, this has been done to make integrating changes more efficient.

As a result, unless a bug is present only in the PHP version, pull requests are unlikely to be accepted unless they are themselves direct transliterations of bugfixes in the Python version.

This port has been marked version 1.0. It is based on the Python version at commit a093f938b7f26564434f3c15a1dcc39e017ad638 <https://github.com/docopt/docopt/commit/a093f938b7f26564434f3c15a1dcc39e017ad638> (labelled 0.6.2).

It has been quite stable for a long time and has barely been changed. The Python version receives only occasional bugfixes and keeping the version numbers pinned has been more trouble than it has been worth.

There are also some major backward compatibility breaks. Rather than dwell in 0.x semver hell, the PHP port will liberally bump major numbers henceforth when BC breaks regardless of the reason.

Please see the Python version's README
for details of any new and breaking changes that are not specific to the PHP version.

There is also at least one significant known issue with the upstream Python version. Due to the porting strategy used for the PHP version, it inherits the bug surface of the Python version (and if it doesn't, that's actually a bug!):


Isn't it awesome how optparse and argparse generate help messages based on your code?!

Hell no! You know what's awesome? It's when the option parser is generated based on the beautiful help message that you write yourself! This way you don't need to write this stupid repeatable parser-code, and instead can write only the help message--the way you want it.

docopt helps you create most beautiful command-line interfaces easily:

Beat that! The option parser is generated based on the docstring above that is passed to docopt function. docopt parses the usage pattern ("Usage: ...") and option descriptions (lines starting with dash "-") and ensures that the program invocation matches the usage pattern; it parses options, arguments and commands based on that. The basic idea is that a good help message has all necessary information in it to make a parser.

Installation

Install docopt.php using Composer:

composer require docopt/docopt

Alternatively, you can just drop docopt.php file into your project--it is self-contained. Get source on github.

docopt.php is tested with PHP 7; it should still work with PHP 5.3+ but this support will become increasingly fragile and will at some point cease to be supported at all. You should update to 7 as soon as you can.

Testing

Configure your repo for running tests:

./dev-setup

You can run unit tests with the following command:

php test.php

This will run the Python language agnostic tests as well as the PHP docopt tests.

API

Docopt::handle() takes 1 required and 1 optional argument:

Docopt\Handler->handle() takes one required argument:

The return value of handle() is a simple associative array with
options, arguments and commands as keys, spelled exactly like in your
help message. Long versions of options are given priority. For example,
if you invoke the top example as:

naval_fate.php ship Guardian move 100 150 --speed=15

the return dictionary will be:

Help message format

Help message consists of 2 sections:

Sections consist of a header and a body. The section body can begin on the same line as the header, but if it spans multiple lines, it must be
indented. A section is terminated by an empty line or a string with no indentation:

Section header: Section body

Section header:
  Section body, which is indented at least
  one space or tab from the section header

Section header: Section body, which is indented at least
  one space or tab from the section header

Usage section format

Minimum example:

Usage: my_program.php

The first word after usage: is interpreted as your program's name. You can specify your program's name several times to signify several exclusive patterns:

Usage: my_program.php FILE
       my_program.php COUNT FILE

Each pattern can consist of the following elements:

Use the following constructs to specify patterns:

If your pattern allows to match argument-less option (a flag) several times:

Usage: my_program.php [-v | -vv | -vvv]

then number of occurrences of the option will be counted. I.e. args['-v'] will be 2 if program was invoked as my_program -vv. Same works for commands.

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: my_program.php <file> <file> --path=<path>...

I.e. invoked with my_program.php file1 file2 --path=./here --path=./there the returned dict will contain args['<file>'] == ['file1', 'file2'] and args['--path'] == ['./here', './there'].

Options section format

The Option section is an optional section that contains a list of
options that can document or supplement your usage pattern.

It is necessary to list option descriptions in order to specify:

The rules are as follows:

Examples

We have an extensive list of examples <https://github.com/docopt/docopt/tree/master/examples> which cover every aspect of functionality of docopt. Try them out, read the source if in doubt.

Subparsers, multi-level help and huge applications (like git)

If you want to split your usage-pattern into several, implement multi-level help (with separate help-screen for each subcommand), want to interface with existing scripts that don't use docopt, or you're building the next "git", you will need the new options_first parameter (described in API section above). To get you started quickly we implemented a subset of git command-line interface as an example: examples/git <https://github.com/docopt/docopt/tree/master/examples/git>

Data validation

docopt does one thing and does it well: it implements your command-line interface. However it does not validate the input data. You should supplement docopt with a validation library when your
validation requirements extend beyond whether input is optional or required.

Development

See the Python version's page for more info
on developing.


All versions of docopt with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package docopt/docopt contains the following files

Loading the files please wait ....