Commit 1502c840 authored by Dirk Eddelbuettel's avatar Dirk Eddelbuettel

Import Upstream version 1.19.1

parent 69307e94
Package: getopt
Type: Package
Title: C-like getopt behavior.
Version: 1.19.0
Version: 1.19.1
Author: Allen Day Contributions from Trevor L Davis
Maintainer: Trevor L Davis <trevor.l.davis@stanford.edu>
Description: Package designed to be used with Rscript to write ``#!''
......@@ -14,7 +14,8 @@ Suggests: testthat
Collate: 'getopt.R'
Repository: CRAN
Repository/R-Forge/Project: optparse
Repository/R-Forge/Revision: 103
Repository/R-Forge/DateTimeStamp: 2012-11-13 01:06:02
Date/Publication: 2012-11-18 09:10:57
Packaged: 2012-11-13 03:24:09 UTC; rforge
Repository/R-Forge/Revision: 116
Repository/R-Forge/DateTimeStamp: 2013-03-01 22:49:51
Date/Publication: 2013-03-04 07:40:03
Packaged: 2013-03-01 23:15:17 UTC; rforge
NeedsCompilation: no
20145b1b405ed63a01fc46365cd98acb *DESCRIPTION
bf4ef0ccdbd56ea20320566ce81af357 *DESCRIPTION
aebacd1e62ffaff4ccc2243969fd06b0 *NAMESPACE
b6f58565c3f316f6521a424f71913930 *NEWS
ade5bad6aeec7c30c9ef1dafc4091456 *R/getopt.R
9189748f22940388cd2c2db25a5751cd *inst/tests/test-getopt.R
96424b4d8b4cc2bdeb2031a954658e77 *NEWS
30b673c833af7a333dab2354bba1ca38 *R/getopt.R
7118628e7508f453e19082f20ed4991e *inst/tests/test-getopt.R
f692f19f2e09013c3d075f6d322473c0 *man/get_Rscript_filename.Rd
7476469866359a385df8551bf79b1cce *man/getopt.Rd
71912d95683c1891b4523acbc554da5e *tests/run-all.R
getopt 1.19.1
=============
* If a passed in option matches multiple options in the getopt specification but matches one exactly
then `getopt` now uses that value instead of throwing a "long flag is ambiguous" error.
getopt 1.19.0
=============
* Exports new function `get_Rscript_filename` that returns name of calling script,
......
......@@ -282,7 +282,11 @@ getopt = function (spec=NULL,opt=commandArgs(TRUE),command=get_Rscript_filename(
#long flag is ambiguous, matches too many options
} else if ( length(rowmatch) > 1 ) {
stop(paste('long flag "', this.flag, '" is ambiguous', sep=''));
# check if there is an exact match and use that
rowmatch = which(this.flag == spec[,col.long.name])
if(length(rowmatch) == 0) {
stop(paste('long flag "', this.flag, '" is ambiguous', sep=''));
}
}
#if we have an argument
......
library("testthat")
library("getopt")
sort_list <- function(unsorted_list) {
for(ii in seq(along=unsorted_list)) {
if(is.list(unsorted_list[[ii]])) {
unsorted_list[[ii]] <- sort_list(unsorted_list[[ii]])
}
}
unsorted_list[sort(names(unsorted_list))]
}
context("Testing getopt")
test_that("getopt works as expected", {
......@@ -13,14 +21,6 @@ test_that("getopt works as expected", {
'sd' , 's', 1, "double",
'output' , 'O', 1, "character"
), ncol=4, byrow=TRUE);
sort_list <- function(unsorted_list) {
for(ii in seq(along=unsorted_list)) {
if(is.list(unsorted_list[[ii]])) {
unsorted_list[[ii]] <- sort_list(unsorted_list[[ii]])
}
}
unsorted_list[sort(names(unsorted_list))]
}
expect_equal(sort_list(getopt(spec, c('-c', '-1', '-m', '-1.2'))),
sort_list(list(ARGS=character(0), count=-1, mean=-1.2)));
expect_equal(sort_list(getopt(spec, c('-v', '-m', '3'))),
......@@ -69,4 +69,16 @@ test_that("getopt works as expected", {
expect_that(print(getopt(spec, c('--date','20080421','--getdata','--market','YM'),usage=TRUE)),
prints_text("Usage: "));
})
test_that("don't throw error if multiple matches match one argument fully", {
# test if partial name matches fully,
# still throw error if multiple matches and doesn't match both fully
# feature request from Jonas Zimmermann
spec = c(
'foo' , 'f', 0, "logical",
'foobar' , 'b', 0, "logical",
'biz' , 'z', 0, "logical"
)
expect_that(getopt(spec, c('--fo')), throws_error())
expect_equal(getopt(spec, c('--foo')), sort_list(list(ARGS=character(0), foo=TRUE)))
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment