Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mishandling of spaces in arguments' values #19

Closed
ajmazurie opened this issue Jun 27, 2016 · 8 comments
Closed

Mishandling of spaces in arguments' values #19

ajmazurie opened this issue Jun 27, 2016 · 8 comments

Comments

@ajmazurie
Copy link

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:

  • ./test.R foo -B "bar baz"
  • ./test.R foo -B 'bar bar'
  • ./test.R foo -b bar baz (this last one to be expected)

Best,
Aurélien

@vforget
Copy link

vforget commented Sep 6, 2016

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
Copy link

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
Copy link

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
Copy link
Member

edwindj commented Jun 14, 2020

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
Copy link

lorenzwalthert commented Jun 14, 2020

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 lorenzwalthert/precommit#178 (comment).

edwindj added a commit that referenced this issue Jun 15, 2020
@edwindj
Copy link
Member

edwindj commented Jun 15, 2020

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.

@edwindj edwindj closed this as completed Jun 15, 2020
@lorenzwalthert
Copy link

Perfect, I'll take a look.

@lorenzwalthert
Copy link

lorenzwalthert commented Jun 15, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants