arrg: Create an argument parser

arrgR Documentation

Create an argument parser

Description

This function creates an argument parser that handles the specified options and usage patterns. To parse arguments or display usage information, the methods parse or show contained in the return value should be called.

Usage

arrg(name, ..., patterns = list(), header = NULL, footer = NULL)

Arguments

name

The name of the command.

...

Option specifications. See opt() for details.

patterns

A list of usage patterns that are valid for the command, each specifying acceptable options and positional arguments. See pat() for details.

header, footer

Optional paragraphs of text to be prepended and/or appended to the usage text produced by the show method of the return value. Typically used to introduce the command or give brief guidance on usage.

Value

A list with function elements

  • parse(args): Parse the character vector of arguments passed in, or by default, the value of commandArgs(trailingOnly=TRUE).

  • show(con, width): Print a usage summary, detailing the valid options and patterns. Text will be printed to the specified connection, default stdout(), and wrapped to the width given, which defaults to the value of the standard width option.

Author(s)

Jon Clayden

See Also

opt(), pat()

Examples

  # A simple parser for a command called "test" with only one option, -h
  p <- arrg("test", opt("h", "Print help"), patterns=list(pat(options="h!")))
  
  # Print out usage information
  p$show()
  
  # Parse the option
  p$parse("-h")

arrg documentation built on Sept. 25, 2024, 5:07 p.m.

Related to arrg in arrg...