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

spaces in --arg stye are not treated as expected #40

Open
lorenzwalthert opened this issue Jun 15, 2020 · 4 comments
Open

spaces in --arg stye are not treated as expected #40

lorenzwalthert opened this issue Jun 15, 2020 · 4 comments

Comments

@lorenzwalthert
Copy link

Unfortunately, #19 does not seem resolved, in fact made things worse for my use case. I caught the command line args with commandArgs(TRUE) so I you should be able to reproduce this easily:

With the CRAN version

#!/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
saveRDS(commandArgs(TRUE), "cmd.rds")

# expected behavior
docopt::docopt(doc, c("--arg=tidyverse_style(scope=\"none\")", "R/test.R"))
#> List of 4
#>  $ --arg  : chr "tidyverse_style(scope=\"none\")"
#>  $ <files>: chr "R/test.R"
#>  $ arg    : chr "tidyverse_style(scope=\"none\")"
#>  $ files  : chr "R/test.R"
#> NULL

# unexpected: I add a space, it does not work anymore
docopt::docopt(doc, c("--arg=tidyverse_style(scope = \"none\")", "R/test.R"))
#> List of 4
#>  $ --arg  : chr "tidyverse_style(scope"
#>  $ <files>: chr [1:3] "=" "none)" "R/test.R"
#>  $ arg    : chr "tidyverse_style(scope"
#>  $ files  : chr [1:3] "=" "none)" "R/test.R"
#> NULL

Created on 2020-06-15 by the reprex package (v0.3.0)

With the GitHub version

#!/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
saveRDS(commandArgs(TRUE), "cmd.rds")

# unexpected: Seems like spaces are removed around 'none'.
docopt::docopt(doc, c("--arg=tidyverse_style(scope=\"none\")", "R/test.R"))
#> List of 4
#>  $ --arg  : chr "tidyverse_style(scope=none)"
#>  $ <files>: chr "R/test.R"
#>  $ arg    : chr "tidyverse_style(scope=none)"
#>  $ files  : chr "R/test.R"
#> NULL

# unexpected: something else went wrong here
docopt::docopt(doc, c("--arg=tidyverse_style(scope = \"none\")", "R/test.R"))
#> List of 4
#>  $ --arg  : chr "tidyverse_style(scope"
#>  $ <files>: chr [1:3] "=" "none)" "R/test.R"
#>  $ arg    : chr "tidyverse_style(scope"
#>  $ files  : chr [1:3] "=" "none)" "R/test.R"
#> NULL

Created on 2020-06-15 by the reprex package (v0.3.0)

@edwindj
Copy link
Member

edwindj commented Jun 16, 2020

Thanks for the quick feedback! I will look into it today

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

edwindj commented Jun 16, 2020

Fixed code does this:

#!/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

# expected behavior
docopt::docopt(doc, c("--arg=tidyverse_style(scope= \"none\")", "R/test.R"))
## List of 4
##  $ --arg  : chr "tidyverse_style(scope= \"none\")"
##  $ <files>: chr "R/test.R"
##  $ arg    : chr "tidyverse_style(scope= \"none\")"
##  $ files  : chr "R/test.R"
## NULL

@lorenzwalthert
Copy link
Author

Looks great, will try in {precommit} tonight. Thanks a ton @edwindj.

@lorenzwalthert
Copy link
Author

lorenzwalthert commented Jun 17, 2020

I did some experimentation, here's what I found:

# works
"--style_transformers=tidyverse_style(scope = \"none\")"
'--style_transformers=tidyverse_style(scope = "none")'
--style_transformers=tidyverse_style(scope = "none")


# does not
'--style_transformers=tidyverse_style(scope = \'none\')'
"--style_transformers=tidyverse_style(scope = 'none')"

So there are more options that work than options that don't work. 😄 Even though things could be further improved, I appreciate all the work @edwindj already put into this and we can call it a day form my side. Will just tell people to the right quotes in the right place.

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

2 participants