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

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

Open karoliskoncevicius opened this issue 9 years ago • 4 comments

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.

karoliskoncevicius avatar Mar 21 '16 00:03 karoliskoncevicius

Thanks for reporting!

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

edwindj avatar Mar 22 '16 15:03 edwindj

I second that!

ramiromagno avatar Nov 06 '20 16:11 ramiromagno

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)

ramiromagno avatar Nov 06 '20 16:11 ramiromagno

Thanks for the suggestion! Will look into it this weekend.

Best,

Edwin

Op vr 6 nov. 2020 17:40 schreef Ramiro Magno [email protected]:

Here's a workaround:

#!/usr/bin/env Rscript 'Naval Fate.Usage: naval_fate.R naval_fate.R ship new ... naval_fate.R ship move [--speed=] naval_fate.R ship shoot naval_fate.R mine (set|remove) [--moored | --drifting] naval_fate.R (-h | --help) naval_fate.R --versionOptions: -h --help Show this screen. --version Show version. --speed= 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)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/docopt/docopt.R/issues/16#issuecomment-723178351, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEEOHEPRK6X36I2F4MBIP3SOQRGRANCNFSM4B6TICWQ .

edwindj avatar Nov 06 '20 19:11 edwindj