stackoverflax
stackoverflax

Reputation: 1107

arguments defaults for docopt

I'm using docopt in R but I expect a python solution will work for me as well.

library(docopt)

doc = 'Usage:
  script.r [<filename>]

Arguments:
  <filename>  The input filename [default: file.txt]
'

docopt(doc)$filename

gives me NULL when what I expect is file.txt. Or to put it another way, I want these two commands to have the same behavior:

Rscript script.r
Rscript script.r file.txt

Upvotes: 1

Views: 1769

Answers (1)

J. P. Petersen
J. P. Petersen

Reputation: 5031

Default values are only for options with an argument like this:

--filename=FILENAME  The input filename [default: file.txt]

Default values can not be specified for arguments. You could maybe change the you program to use an option with an argument instead?

Upvotes: 2

Related Questions