docopt: Parse 'args' based on command-line interface described in...

Description Usage Arguments Value References Examples

View source: R/docopt.R

Description

docopt creates your command-line interface based on its description that you pass as doc. Such description can contain –options, <positional-argument>, commands, which could be [optional], (required), (mutually | exclusive) or repeated...

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
docopt(
  doc,
  args = commandArgs(TRUE),
  name = NULL,
  help = TRUE,
  version = NULL,
  strict = FALSE,
  strip_names = !strict,
  quoted_args = !strict
)

Arguments

doc

character vector with command line specification

args

character vector of commandline arguments. If args is missing commandArgs(trailingOnly=TRUE) will be used.

name

Currently not used

help

logical should "-h" or "–help" generate a usage string?

version

character. If supplied the option "-v" generates the given version number and stops.

strict

logical if TRUE docopt will conform to docopt.py in and output (strip_names=FALSE and quoted_args=FALSE)

strip_names

if TRUE it will remove dashes and angles from the resulting names and add these to the resulting list. Note that this is different from docopt standard!

quoted_args

if TRUE it will accept quoted arguments. Note that this is different from docopt standard!

Value

named list with all parsed options, arguments and commands.

References

http://docopt.org,

Examples

1
2
3
4
5
6
7
8
"Usage: my_program.R [-hso FILE] [--quiet | --verbose] [INPUT ...]

-h --help    show this
-s --sorted  sorted output
-o FILE      specify output file [default: ./test.txt]
--quiet      print less text
--verbose    print more text" -> doc
docopt(doc, "-s --quiet")

Example output

List of 11
 $ --help   : logi FALSE
 $ --sorted : logi TRUE
 $ -o       : chr "./test.txt"
 $ --quiet  : logi TRUE
 $ --verbose: logi FALSE
 $ INPUT    : list()
 $ help     : logi FALSE
 $ sorted   : logi TRUE
 $ o        : chr "./test.txt"
 $ quiet    : logi TRUE
 $ verbose  : logi FALSE
NULL

docopt documentation built on July 1, 2020, 7:10 p.m.