Skip to content

passing named ... through docopt #43

@lorenzwalthert

Description

@lorenzwalthert

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions