A Subparsers R6 object wraps the Python argparse object used to add
sub-commands.
Objects of this class are returned by the add_subparsers() method of
Parser objects.
Methods
Subparsers$new()
Create a new Subparsers object.
Users should not call this directly but instead use the add_subparsers() method of a Parser object.
Usage
Subparsers$new(python_code, name)Subparsers$add_parser()
Add a sub-command parser.
Arguments
...Arguments cleaned and passed to Python's
add_parser()method. The first argument is usually the name of the sub-command. Accepts the same arguments asArgumentParser()as well ashelpandaliases.
Returns
A Parser object.
Examples
if (argparse:::detects_python()) {
parser <- ArgumentParser(prog = "PROG")
parser$add_argument("--foo", action = "store_true", help = "foo help")
subparsers <- parser$add_subparsers(help = "sub-command help")
parser_a <- subparsers$add_parser("a", help = "a help")
parser_a$add_argument("bar", type = "integer", help = "bar help")
parser$parse_args(c("a", "12"))
}
#> $bar
#> [1] 12
#>
#> $foo
#> [1] FALSE
#>