docopt.R icon indicating copy to clipboard operation
docopt.R copied to clipboard

passing named ... through docopt

Open lorenzwalthert opened this issue 5 years ago • 1 comments

Thanks for this useful package. I'd like to pass arguments to docopt for which the name have not explicitly defined (becauuse they are dynamic). In R, we know the concept of an ellipse (...). I imagine it to work similar to this:

./inst/bin/style-files --style_pkg=1 --stle_fun=3 --key=1 --value2=67 f1 f2

But I get an error.

Error: style files.
Usage:
  style_files [--style_pkg=<style_guide_pkg>] [--style_fun=<style_guide_fun>] <files>...

Options:
  --style_pkg=<style_guide_pkg>  Package where the style guide is stored [default: styler].
  --style_fun=<style_guide_fun>  The styling function in style_pkg [default: tidyverse_style].

Execution halted

Is there any way to do this? Or can you maybe expose the parser so I can parse the arguments without matching them to the docs?

Here is my script:

#!/usr/bin/env Rscript

'style files.
Usage:
  style_files [--style_pkg=<style_guide_pkg>] [--style_fun=<style_guide_fun>] <files>...

Options:
  --style_pkg=<style_guide_pkg>  Package where the style guide is stored [default: styler].
  --style_fun=<style_guide_fun>  The styling function in style_pkg [default: tidyverse_style].

' -> doc

saveRDS(commandArgs(), 'cmd.rds')

I note that ... matches unnamed arguments here, but I'd like to pass named ones.

lorenzwalthert avatar Sep 16 '20 09:09 lorenzwalthert

Maybe we can extend the syntax? like ...<dots> to match named arguments, as an extension to <dots>...?

lorenzwalthert avatar Sep 16 '20 09:09 lorenzwalthert