docopt / docopt.R

Command-line interface description language for R (http://docopt.org)
Other
210 stars 17 forks source link

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

Open karoliskoncevicius opened 8 years ago

karoliskoncevicius commented 8 years ago

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 commented 8 years ago

Thanks for reporting!

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

ramiromagno commented 4 years ago

I second that!

ramiromagno commented 4 years ago

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 commented 4 years ago

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

Best,

Edwin

Op vr 6 nov. 2020 17:40 schreef Ramiro Magno notifications@github.com:

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 .