Skip to content

Commit 1834de2

Browse files
committed
fix for issue #44, thanks to @igordot and @eddelbuettel
1 parent ebdeb31 commit 1834de2

5 files changed

Lines changed: 67 additions & 2 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ BugReports: https://github.com/docopt/docopt.R/issues
1212
Imports: methods
1313
Suggests:
1414
testthat
15-
RoxygenNote: 7.1.0
15+
RoxygenNote: 7.3.2
16+
Encoding: UTF-8

R/docopt.R

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,25 @@ docopt <- function( doc, args=commandArgs(TRUE), name=NULL, help=TRUE, version=N
8787
}
8888
return(dict)
8989
}
90-
stop(doc, call. = FALSE)
90+
help(doc)
91+
if (length(m$left) == 0){
92+
stop("Missing argument(s)", call. = FALSE)
93+
}
94+
95+
m_args <- lapply(m$left, function(o){
96+
if (!is.null(o$short)){
97+
return(o$short)
98+
}
99+
if (!is.null(o$long)){
100+
return(o$long)
101+
}
102+
""
103+
}) |>
104+
sQuote() |>
105+
paste(collapse=", ")
106+
107+
stop("Unknown arguments: ",m_args, call. = FALSE)
108+
# stop(doc, call. = FALSE)
91109
#stop(paste("\n",usage, collapse="\n "), call. = FALSE)
92110
}
93111

docopt.Rproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version: 1.0
2+
ProjectId: 696c4343-cab8-4df7-9aec-d8fd3343dd98
23

34
RestoreWorkspace: Default
45
SaveWorkspace: Default

man/docopt-package.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-issue44.R

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
doc <-
2+
"Naval Fate.
3+
4+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
5+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
6+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
7+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
8+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
9+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
10+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
11+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
12+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
13+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
14+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
15+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
16+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
17+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
18+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
19+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
20+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
21+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
22+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
23+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
24+
lots of text lots of text lots of text lots of text lots of text lots of text lots of text
25+
26+
Usage:
27+
naval_fate ship new <name>...
28+
naval_fate ship <name> move <x> <y> [--speed=<kn>]
29+
naval_fate ship shoot <x> <y>
30+
naval_fate mine (set|remove) <x> <y> [--moored|--drifting]
31+
naval_fate -h | --help
32+
naval_fate --version
33+
34+
Options:
35+
-h --help Show this screen.
36+
--version Show version.
37+
--speed=<kn> Speed in knots [default: 10].
38+
--moored Moored (anchored) mine.
39+
--drifting Drifting mine.
40+
"
41+
42+
expect_error(
43+
d <- docopt(doc)
44+
)

0 commit comments

Comments
 (0)