Skip to content

Commit

Permalink
Remove 'default' argument from reg_positionals_list()
Browse files Browse the repository at this point in the history
  • Loading branch information
jperkel committed Feb 12, 2022
1 parent 5af8948 commit afc6d86
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 7 additions & 7 deletions R/parse_command_line.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -126,17 +126,17 @@ $command
[1] "add"
$subcmd
[1] "file"
$unknowns
[1] "-z"
[1] "name"
$daterange1
[1] "2020"
$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:
Expand Down
2 changes: 1 addition & 1 deletion man/parse_date.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/reg_positionals_list.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions test_cmdparseR.R
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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)

Expand Down

0 comments on commit afc6d86

Please sign in to comment.