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

Print full --help message on error when no arguments are passed? #16

Open
karoliskoncevicius opened this issue Mar 21, 2016 · 4 comments

Comments

@karoliskoncevicius
Copy link

First of all - big thank you to the authors of this package. My scripts became 100 lines lighter and less bug-prone.

My issue is with the failing message of the script when no arguments are passed. Right now it prints this kind of message:

Error in docopt(doc): usage: ...
Execution halted

Can instead of printing this rather cryptic error the script simply print out the full --help message? Or maybe just the simple "usage:" line without the "Error in docopt"? Coming from optparse this is the only thing I miss. Maybe there is already a way around that?

Thanks a lot.

@edwindj
Copy link
Member

edwindj commented Mar 22, 2016

Thanks for reporting!

I'll look into it this week: should be fixable :-)

@ramiromagno
Copy link

I second that!

@ramiromagno
Copy link

Here's a workaround:

#!/usr/bin/env Rscript

'Naval Fate.

Usage:
  naval_fate.R
  naval_fate.R ship new <name>...
  naval_fate.R ship <name> move <x> <y> [--speed=<kn>]
  naval_fate.R ship shoot <x> <y>
  naval_fate.R mine (set|remove) <x> <y> [--moored | --drifting]
  naval_fate.R (-h | --help)
  naval_fate.R --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.

' -> doc

if(length(commandArgs(trailingOnly = TRUE)) == 0L) {
  docopt:::help(doc)
  quit()
}

library(docopt)
arguments <- docopt(doc, version = 'Naval Fate 2.0')
print(arguments)

@edwindj
Copy link
Member

edwindj commented Nov 6, 2020 via email

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

No branches or pull requests

3 participants