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

Linewrap usage line?

Open shabbybanks opened this issue 6 years ago • 4 comments

It is often natural to split up the Usage line based on length when there are multiple options, but this is apparently not possible? The following MWE:

library(docopt)
doc <- "Usage: example.r [-a <ABCEDARIAN>] [-b <BOTHER>] [-t <TOOLONG>] [-q <QUIT_ALREADY>] \
 [-O <OOOPS>]
-a ABCEDARIAN               just an example. [default: abcde]
-b BOTHER                   just an example. [default: bother]
-t TOOLONG                  just an example. [default: 1234]
-q QUIT_ALREADY             just an example. [default: noquit]
-O OOOPS                    just an example. [default: ooops]
"
opt <- docopt(doc,args='-O nofooz')

yields the error

Error:
 usage: example.r [-a <ABCEDARIAN>] [-b <BOTHER>] [-t <TOOLONG>] [-q <QUIT_ALREADY>]

I have tried dropping the backslash, doubling the backslash, adding another Usage: prefix (which causes a different error about multiple Usage: lines) and so on.

sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server release 6.9 (Santiago)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] docopt_0.4.5   fortunes_1.5-4 drat_0.1.2

loaded via a namespace (and not attached):
[1] magrittr_1.5  tools_3.2.2   stringi_1.1.5 stringr_1.2.0

(see also https://github.com/docopt/docopt/issues/130 , which was of no help).

shabbybanks avatar Jul 14 '17 18:07 shabbybanks

My proposed fix would be to optionally allow compatibility with Python (and docopt 'standard' as of 0.6) where Usage: starts the usage stanza and Options: starts the option stanza. Allow the old standard for backwards compatibility, but move towards deprecating it: a mild warning in 2 releases, a stronger warning in 4, and deprecated in 6, or what have you. See also docopt docs.

shabbybanks avatar Jul 14 '17 21:07 shabbybanks

Thanks for the suggestion: I will look into it at the end of this week.

Best,

Edwin

edwindj avatar Jul 18 '17 20:07 edwindj

Any update on this feature?

Got a work aroung with this:

doc <- gsub(pattern = "\n {2,}", replacement = " ", x = doc)

dweemx avatar Dec 20 '18 10:12 dweemx