diff --git a/DESCRIPTION b/DESCRIPTION index f2f9390..a6092af 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: cmdparseR Title: Command Line Parser -Version: 0.1.2 +Version: 0.1.3 Authors@R: person(given = "Jeffrey", family = "Perkel", diff --git a/R/parse_command_line.R b/R/parse_command_line.R index a99c1d4..bc764b4 100644 --- a/R/parse_command_line.R +++ b/R/parse_command_line.R @@ -307,25 +307,25 @@ reg_argument_list <- function(plist) { # # Register a 'positional' command line argument (ie, the last argument in the list) -reg_positionals <- function(var, default, help) { - reg_argument (lparam = NA, sparam = NA, var = var, default = default, argType = argsType$TypePositional, help = help) +reg_positionals <- function(var, help) { + reg_argument (lparam = NA, sparam = NA, var = var, default = NA, argType = argsType$TypePositional, help = help) } # reg_positionals #' Register a list of 'positional' arguments #' -#' @param plist list of positional arguments: variable name, default value, help text +#' @param plist list of positional arguments: variable name, help text #' #' @export #' #' @examples -#' args <- list(c("infile",NA,"input file")) +#' args <- list(c("infile","input file")) reg_positionals_list <- function(plist) { - ids <- c("var","default","help") + ids <- c("var","help") for (p in plist) { stopifnot(length(p) == length(ids)) - reg_positionals(var = p[1], default = p[2], help = p[3]) + reg_positionals(var = p[1], help = p[2]) } } # reg_positionals_list @@ -334,7 +334,7 @@ reg_positionals_list <- function(plist) { #' #' @param d the date to parse (string) #' -#' @return A tuple: c(y, m, d) +#' @return A vector: c(y, m, d) #' @export #' #' @examples diff --git a/README.md b/README.md index c0509ec..27d8ae7 100644 --- a/README.md +++ b/README.md @@ -73,9 +73,9 @@ main <- function() { reg_argument_list(args) pos <- list( - # variable name, default, help string - c('outfile',NA,'Output filename'), - c('infiles',NA,'Input filename(s)') + # variable name, help string + c('outfile','Output filename'), + c('infiles','Input filename(s)') ) reg_positionals_list(pos) @@ -91,18 +91,18 @@ main() Invoked like so: ``` -Rscript test_cmdparser.R add file -c ~/tmp/config.txt -d -vvv -k key1 -k key2 -z -r 2020:2022 outfile.txt infile1.txt infile2.txt infile3.txt +Rscript test_cmdparseR.R add name -dvvv -r 2020:2022 -z -k key1 -k key2 outfile.txt infile1.txt infile2.txt infile3.txt ``` you should see the following: ``` -$ Rscript test_cmdparser.R add file -c ~/tmp/config.txt -d -vvv -k key1 -k key2 -z -r 2020:2022 outfile.txt infile1.txt infile2.txt infile3.txt +$ Rscript test_cmdparseR.R add name -dvvv -r 2020:2022 -z -k key1 -k key2 outfile.txt infile1.txt infile2.txt infile3.txt Warning: parse_command_line(): unknown param: -z $help [1] "FALSE" $config -[1] "~/Users/username/tmp/config.txt" +[1] "~/myconfigfile.txt" $debug [1] TRUE @@ -126,10 +126,7 @@ $command [1] "add" $subcmd -[1] "file" - -$unknowns -[1] "-z" +[1] "name" $daterange1 [1] "2020" @@ -137,6 +134,9 @@ $daterange1 $daterange2 [1] "2022" +$unknowns +[1] "-z" + ``` `cmdparseR` provides a `usage()` function to create a formatted help message based on the `desc` strings passed to `reg_argument_list()`, `reg_command_list()` and `reg_subcmd_list()`. By default, `--help` or `-?` on the command line will call this function: diff --git a/man/parse_date.Rd b/man/parse_date.Rd index 26cd49f..616e282 100644 --- a/man/parse_date.Rd +++ b/man/parse_date.Rd @@ -10,7 +10,7 @@ parse_date(d) \item{d}{the date to parse (string)} } \value{ -A tuple: c(y, m, d) +A vector: c(y, m, d) } \description{ Parses a date in YYYY-MM-DD, YYYYMMDD, YYYY-MM or YYYY format diff --git a/man/reg_positionals_list.Rd b/man/reg_positionals_list.Rd index fa6dc68..e047999 100644 --- a/man/reg_positionals_list.Rd +++ b/man/reg_positionals_list.Rd @@ -7,11 +7,11 @@ reg_positionals_list(plist) } \arguments{ -\item{plist}{list of positional arguments: variable name, default value, help text} +\item{plist}{list of positional arguments: variable name, help text} } \description{ Register a list of 'positional' arguments } \examples{ -args <- list(c("infile",NA,"input file")) +args <- list(c("infile","input file")) } diff --git a/test_cmdparseR.R b/test_cmdparseR.R index fd4fb2e..3846991 100644 --- a/test_cmdparseR.R +++ b/test_cmdparseR.R @@ -8,7 +8,7 @@ main <- function() { c('delete', 'Delete something') ) reg_command_list(cmds) - + subcmds <- list( c('name','add','Add a name'), c('file','add','Add a file'), @@ -27,8 +27,8 @@ main <- function() { reg_argument_list(args) pos <- list( - c('outfile',NA,'Output filename'), - c('infiles',NA,'Input filename(s)') + c('outfile','Output filename'), + c('infiles','Input filename(s)') ) reg_positionals_list(pos)