argparse Module

Overview

Members

namespace argparse

test DOCUMENTING THE NAMESPACE

Functions

bool checkOption(string name, int argc, char *argv[])

Parses through arguments and checks if an option/flag exists.

Parameters:
  • namestring to match option with

  • argcint representing the number of arguments

  • argv – array of char arrays, representing string arguments

Returns:

bool representing whether the flag exists.

string getStringArg(string name, int argc, char *argv[], string usage = "")

Gets the value of an argument option as a string

Parses through arguments, and returns value of matching name of the format:

             <option> <value>

Where <option> is matched to name. This functions exits when the option isn’t found, and prints an optional usage message

Parameters:
  • namestring to match option with

  • argcint indicating the number of arguments

  • argv – array of char arrays, representing string arguments

  • usagestring representing an optional usage message, printed upon failure, default=""

Returns:

string

int getIntArg(string name, int argc, char *argv[], string usage = "")

Gets the value of an argument option as an int

Parses through arguments, and returns value of matching name of the format:

             <option> <value>

Where <option> is matched to name. This functions exits when the option isn’t found, and prints an optional usage message

Parameters:
  • namestring to match option with

  • argcint indicating the number of arguments

  • argv – array of char arrays, representing string arguments

  • usagestring representing an optional usage message, printed upon failure, default=""

Returns:

int

float getFloatArg(string name, int argc, char *argv[], string usage = "")

Gets the value of an argument option as an float

Parses through arguments, and returns value of matching name of the format:

             <option> <value>

Where <option> is matched to name. This functions exits when the option isn’t found, and prints an optional usage message

Parameters:
  • namestring to match option with

  • argcint indicating the number of arguments

  • argv – array of char arrays, representing string arguments

  • usagestring representing an optional usage message, printed upon failure, default=""

Returns:

float

string getStringArgSecure(string name, string defaultValue, int argc, char *argv[])

Gets the value of an argument option as a string

Parses through arguments, and returns value of matching name of the format:

             <option> <value>

Where <option> is matched to name.

Parameters:
  • namestring to match option with

  • defaultValuestring representing the default value if the option isn’t found

  • argcint indicating the number of arguments

  • argv – array of char arrays, representing string arguments

Returns:

string; will return defaultValue if the option isn’t found

int getIntArgSecure(string name, int defaultValue, int argc, char *argv[])

Gets the value of an argument option as a int

Parses through arguments, and returns value of matching name of the format:

             <option> <value>

Where <option> is matched to name.

Parameters:
  • namestring to match option with

  • defaultValueint representing the default value if the option isn’t found

  • argcint indicating the number of arguments

  • argv – array of char arrays, representing string arguments

Returns:

int; will return defaultValue if the option isn’t found

float getFloatArgSecure(string name, float defaultValue, int argc, char *argv[])

Gets the value of an argument option as a float

Parses through arguments, and returns value of matching name of the format:

             <option> <value>

Where <option> is matched to name.

Parameters:
  • namestring to match option with

  • defaultValuefloat representing the default value if the option isn’t found

  • argcint indicating the number of arguments

  • argv – array of char arrays, representing string arguments

Returns:

float; will return defaultValue if the option isn’t found