docopt / docopt.R

Command-line interface description language for R (http://docopt.org)
Other
210 stars 17 forks source link

Mishandling of spaces in arguments' values #19

Closed ajmazurie closed 4 years ago

ajmazurie commented 8 years ago

Hi guys, I cannot seem to have doctopt to properly handle argument values that contain spaces. Here is a reproducible example:

#!/usr/bin/env Rscript --vanilla

library("docopt")

"usage: test.R <A> [options]

 <A>            Dummy positional argument
 -B <value>...  Dummy optional argument
" -> syntax

print(docopt::docopt(syntax))

If I call this script with ./test.R foo -B bar, everything is fine. But the following are considered errors:

Best, Aurélien

vforget commented 8 years ago

Same issue here. Might be related, see

http://stackoverflow.com/questions/26130724/how-to-pass-a-docopt-argument-where-the-argument-is-a-string-with-spaces-in-pyth.

Edit: Actually, issue on my code is with use of the =. For instance, error occurs when I use --arg= 'some string', but works when I do --arg 'some string'.

barryrowlingson commented 6 years ago

Two years have passed, and the OPs script above seems to work for me. I have other space-related problems but this issue might warrant closing.

lorenzwalthert commented 4 years ago

agree with @vforget. Here's a reprex:

#!/usr/bin/env Rscript

'style files.
Usage:
  style_files [--arg=<arg1>] <files>...

Options:
  --arg=<arg1>  Package where the style guide is stored [default: Arg1].

' -> doc

arguments <- docopt::docopt(doc)
print(arguments)
saveRDS(arguments, 'argument.rds')

No problem here:

(base) lorenz precommit $ ~/short-term/docopt-error --arg='ab' f1 f2                                √ 22:57:33
List of 4
 $ --arg  : chr "ab"
 $ <files>: chr [1:2] "f1" "f2"
 $ arg    : chr "ab"
 $ files  : chr [1:2] "f1" "f2"
NULL

But this does not work:

(base) lorenz precommit $ ~/short-term/docopt-error --arg='a b' f1 f2                              ×1 22:56:34
List of 4
 $ --arg  : chr "Arg1"
 $ <files>: chr [1:3] "--arg=a b" "f1" "f2"
 $ arg    : chr "Arg1"
 $ files  : chr [1:3] "--arg=a b" "f1" "f2"
NULL
edwindj commented 4 years ago

Thanks for reporting! I am looking into it! FWIW:

~/short-term/docopt-error --arg 'a b' f1 f2       

(without the assignment sign), does work.

lorenzwalthert commented 4 years ago

Jup, true. Thanks @edwindj, it would be awesome to see this fixed. If it motivates you: this edge case will be used in {precommit} to allow people to select the style guide for formatting, as described in https://github.com/lorenzwalthert/precommit/issues/178#issuecomment-643736898.

edwindj commented 4 years ago

I seem to have fixed the issue. Please reopen if necessary :-) I will upload this version to CRAN on Wednesday. So please let me know if this fix is breaking other stuff.

lorenzwalthert commented 4 years ago

Perfect, I'll take a look.

lorenzwalthert commented 4 years ago

Unfortunately not -.-, I filed #40 to describe exactly what does not work as expected.