Parser for command-line options and arguments

Description

Parser for command-line options and arguments

Fields

cmdargs

list

exeargs

character

args

list

types

list

defaults

list

helps

list

usage

character

description

character

Methods

add_argument(name, ..., type, default, required = FALSE, help = "", dest, action)

Add an argument.

add_description(x)

Add a description.

add_usage(x)

Add a usage.

make_help()

Make and display ‘usage’.

Author(s)

Xiaobei Zhao

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
## Test
require(Xmisc)
parser <- ArgumentParser$new()
parser$add_argument('--a_str',type='character')
parser$add_argument('--b_num',type='numeric',default='0')
a_str
## character(0)
b_num
## [1] 0
message(parser$get_help())
## Usage:
##     /bin/exec/R ...
## Description:
## Options:
##     a_str character
##     b_num numeric   [ 0 ]

## Not run: 
## Test from a command line
R -q -e "
require(methods);require(Xmisc);
parser <- ArgumentParser\$new();
parser\$add_argument('--a_str',type='character');
parser\$add_argument('--b_num',type='numeric',default='0');
printme(a_str);printme(b_num);parser\$get_help();
" --args --a_str='Hello World!' --b_num=1
## Loading required package: Xmisc
## ## a_str ##
## [1] "Hello World!"
## ## b_num ##
## [1] 1
## ...

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.