-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_cmdparseR.R
59 lines (50 loc) · 2.29 KB
/
test_cmdparseR.R
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# library(cmdparseR)
main <- function() {
init_command_line_parser('test_cmdparseR','Test cmdparseR package','0.1.0')
cmds <- list(
list('add', 'Add something'),
list('delete', 'Delete something')
)
reg_command_list(cmds)
subcmds <- list(
list('name','add','Add a name'),
list('file','add','Add a file'),
list('name','delete','Delete a name'),
list('file','delete','Delete a file')
)
reg_subcmd_list(subcmds)
args <- list(
list('--config','-c','config','~/myconfigfile.txt',argsType$TypeValue,'Configuration file'),
list('--debug','-d','debug',FALSE,argsType$TypeBool,'Display debug messages'),
list('--keywords','-k','keywords',NA,argsType$TypeMultiVal,'Search keywords'),
list('--daterange','-r','daterange',NA,argsType$TypeRange,'Date range'),
list('--long-help-text',NA,'longhelptext',NA,argsType$TypeBool,
'The unanimous Declaration of the thirteen united States of America, When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Natures God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.'),
list('--username','-u','username',NA,argsType$TypeValue,'User name'),
list('--verbose','-v','verbose',0,argsType$TypeCount,'Verbosity level')
)
reg_argument_list(args)
pos <- list(
list('outfile','Output filename. 12345678901234567890123456789012345678901234567890123456789012345678901234567890'),
list('infiles','Input filename(s)')
)
reg_positionals_list(pos)
args <- commandArgs(trailingOnly = TRUE)
mydata <- parse_command_line(args, default_help = FALSE)
if (mydata$help) {
writeLines(paste0("Command: ", mydata$command))
writeLines(paste0("Subcmd: ", mydata$subcmd))
usage()
stop(call. = FALSE)
}
if (is.na(mydata$outfile)) stop("Error: no outfile provided.")
# read input from stdin if no input files provided on the cmd line.
if (is.na(mydata$infiles[1])) {
stdin <- file("stdin")
lines <- readLines(stdin)
close(stdin)
mydata$infiles <- lines
}
print(mydata)
}
if (!interactive()) main()