add.argument: Declare a Formal Argument for an Argument Parser

add.argumentR Documentation

Declare a Formal Argument for an Argument Parser

Description

Set the formal arguments of an ArgumentParser.

Usage

## S4 method for signature 'essentials_ArgumentParser'
add.argument(..., action = NULL, nargs = NULL, constant, default,
    type = "any", choices = NULL, required = NA, help = NA,
    metavariable = NA, destination = NA, wrap = TRUE,
    overwrite = getOption("essentials.overwrite", TRUE))

Arguments

...

character vector. A name for a positional argument or a set of flags for an optional argument.

action

character string. One of "store", "store_const", "store_true", "store_false", "append", "count", "help", "exit", and "skip", indicating what to do when this argument is encountered.

nargs

number of arguments expected for this formal argument. A positive number specifying exactly the accepted number of arguments, two numbers specifying the range of the accepted number of arguments, or a character string indicating the accepted number of arguments, see Details.

constant

for action "store_const", the object to be stored when this argument is encountered.

default

object to be stored when this argument is not encountered.

type

character string naming an atomic mode or "list" or "expression" or "any". If "any", the appropriate type is decided based on action and default.

choices
required

logical. Is this argument required?

help

character vector. A brief description of the formal argument.

metavariable

character string. A name for the value in usage messages.

destination

character string. A name for the assigned value returned by parse.args.

wrap

logical. Should the usage message help be wrapped when printing the help message for the argument parser?

overwrite

logical. If the name or flags are already in use, should they be replaced by this new definition?

Details

A positional argument is an argument in which the name of argument is not specified before its value (its value is assigned to the next available positional argument). The other types of arguments are arguments specified by a leading flag, either a short flag or a long flag.

action is an instruction for what to do when this argument is found at the command-line:

action = "store"

Stores the argument's value. When multiple values are provided, the last value is stored and the others are discarded.

action = "store_const"

If this argument is provided, constant is stored, otherwise default is stored.

action = "store_true", "store_false"

Special cases of action = "store_const" in which constant = TRUE, default = FALSE and constant = FALSE, default = TRUE, respectively. default can be overwritten for special cases.

action = "append"

Stores the argument's value. When multiple values are provided, the values are appended and stored together.

action = "count"

Store the number of times this argument was provided.

action = "help"

Print the help message and exit the program.

action = "exit"

Print an exit message and exit the program.

action = "skip"

Skip the rest of the commmand line (the following arguments are for another program).

nargs can be specified in three manners:

  • A positive number, the exact number of arguments that must be provided. Specifying nargs in this manner does not make sense with action "store_const", "store_true", "store_false", and "count", or with action "store" when nargs is greater than 1, and will throw a warning.

  • Two non-negative numbers, a lower and upper bound on the number of arguments that must be provided. Specifying 0 as the lower bound indicates no lower limit, and Inf as the upper bound indicates no upper limit.

  • A character string, specifically one of the regex repetition quantifiers:

    ?

    At most one argument.

    *

    Zero or more arguments.

    +

    One or more arguments.

    {n}

    Exactly n arguments.

    {n,}

    At least n arguments.

    {n,m}

    At least n arguments, at most m arguments.

When nargs is NULL, required is used in its place.

Value

Invisible NULL.


ArcadeAntics/essentials documentation built on Nov. 7, 2024, 4:33 p.m.