Skip to content

Commit 5af8948

Browse files
authored
Update README.md
1 parent dd1cd95 commit 5af8948

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ To use, call `init_command_line_parser()` to initialize the parsing tool. Then c
1313

1414
Given a command line such as `Rscript MyCheckbook.R withdraw cash --amount=100 --msg='birthday gift'`, `withdraw` is the command, `cash` is a subcommand and `--amount=100` and `--msg='birthday gift'` are arguments. You might also add a `deposit` command, and a `check` subcommand, eg `MyCheckbook.R withdraw check --number=123 --amount=50 --payee='Electric Co.'` to log a check to the electric company.)
1515

16-
Note that the user need not provide all registered arguments on the command line. The default parameter passed to `reg_argument_list()` preloads the default. Thus, you could have an argument whose default value is FALSE. When `parse_command_line()` is called, the variable will be set to FALSE, unless the user includes in the command line, in which case it flips to TRUE.
16+
Note that the user need not provide all registered arguments on the command line. The default parameter passed to `reg_argument_list()` preloads the default.
1717

1818
When registering arguments, you must indicate the type of value you expect to receive. Valid parameter types are:
1919
- `argsType$TypeBool` for Boolean values. Using the argument flips the default value. Thus, if the default value of `--plot` is `FALSE`, including `--plot` on the command line will set its value to `TRUE`. Arguments of the form `--plot=TRUE` and `--plot=F` are also allowed.
@@ -43,15 +43,18 @@ The file `test_cmdparseR.R` provides a simple example:
4343
library(cmdparseR)
4444

4545
main <- function() {
46+
# script name, script description, version number
4647
init_command_line_parser('test_cmdparseR','Test cmdparseR package','0.1.0')
4748

4849
cmds <- list(
50+
# command, help string
4951
c('add', 'Add something'),
5052
c('delete', 'Delete something')
5153
)
5254
reg_command_list(cmds)
5355

5456
subcmds <- list(
57+
# subcommand, parent command, help string
5558
c('name','add','Add a name'),
5659
c('file','add','Add a file'),
5760
c('name','delete','Delete a name'),
@@ -60,6 +63,7 @@ main <- function() {
6063
reg_subcmd_list(subcmds)
6164

6265
args <- list(
66+
# long parameter form, short parameter form, variable name, default value, argument type, help string
6367
c('--config','-c','config','~/myconfigfile.txt',argsType$TypeValue,'Configuration file'),
6468
c('--debug','-d','debug',FALSE,argsType$TypeBool,'Display debug messages'),
6569
c('--keywords','-k','keywords',NA,argsType$TypeMultiVal,'Search keywords'),
@@ -69,6 +73,7 @@ main <- function() {
6973
reg_argument_list(args)
7074

7175
pos <- list(
76+
# variable name, default, help string
7277
c('outfile',NA,'Output filename'),
7378
c('infiles',NA,'Input filename(s)')
7479
)

0 commit comments

Comments
 (0)