Command-Line Interface Specification Language

Define a command-line interface by just giving it a description in the specific format.


version downloads Build Status

docopt helps you to:

  • define an interface for your command-line app, and
  • automatically generate a parser for it.

For more information see docopt.org

R package docopt is an implementation of docopt in the R language. See my presentation on the useR! 2014 for more details.

Install

The latest version of docopt can be installed using:

library(devtools)  # make sure to have devtools 1.4!
install_github("docopt/docopt.R")

It is tested against the tests defined for the reference implementation. It passes most tests. It currently fails tests that

  • count arguments: my_prog.R -v -v should return list(v=2)

The tests can be run using devtools test() and can be found in "inst/tests"

Usage

docopt uses the description of the command-line interface to parse command line arguments.

'usage: my_prog.R [-a -r -m <msg>]
 
options:
 -a        Add
 -r        Remote
 -m <msg>  Message' -> doc
library(docopt)
# retrieve the command-line arguments
opts <- docopt(doc)
# what are the options? Note that stripped versions of the parameters are added to the returned list
str(opts)  
## List of 3
##  $ -a: logi FALSE
##  $ -r: logi FALSE
##  $ -m: chr "<msg>"
##  $ a: logi FALSE
##  $ r: logi FALSE
##  $ m: chr "<msg>"
 
# or set them manually
opts <- docopt(doc, "-m Hello")
str(opts)
## List of 3
##  $ -a: logi FALSE
##  $ -r: logi FALSE
##  $ -m: chr "Hello"
##  $ a: logi FALSE
##  $ r: logi FALSE
##  $ m: chr "Hello"

Note

There is an issue with using -g and -gui with docopt.R as reported on Stackoverflow. Rscript filters on -g and -gui before docopt.R can access them.

News

version 0.4.5

  • Fixed single argument which embed a space (issue #11, thanks to @malcook)

version 0.4.4

  • Fixed arguments which embed a space (issue #11, thanks to @jennybc)
  • Added print method for docopt (issue @12, thanks to @eddelbuettel)

version 0.4.3.1

  • Fixed stringr dependency thanks to (@eddelbuettel)

version 0.4

  • Fixed repeating options (issue #8, thanks to @cboettig)
  • Fixed parsing after double -- (thanks to @ljos)
  • Fixed printing multiple usage statements (issue #7, thanks to @rgrannell1)

version 0.3

  • Breaking change! By default stripped names (no dashes and angles) are added to the return list
  • added support for quoted strings as arguments (thanks to @aniketschneider/issue #4)
  • added extra "\n" to --help output (thanks to @eddelbuettel)
  • added strip_names to docopt (suggestion of @eddelbuettel)
  • changed "Imports: methods"" into "Depends: methods" (thanks to @pschulam)

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("docopt")

0.6.1 by Edwin de Jonge, 9 days ago


https://github.com/docopt/docopt.R


Report a bug at https://github.com/docopt/docopt.R/issues


Browse source code at https://github.com/cran/docopt


Authors: Edwin de Jonge ([email protected])


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports methods

Suggests testthat


Imported by jetpack, qlcData, qlcMatrix.

Suggested by littler, prrd.


See at CRAN