Pakman
Arguments Class Reference

#include <Arguments.h>

Public Member Functions

 Arguments (const LongOptions &long_options, int argc, char *argv[])
 
 ~Arguments ()=default
 
bool isOptionalArgumentSet (const std::string &option_name) const
 
std::string optionalArgument (const std::string &option_name) const
 
int numberOfPositionalArguments () const
 
std::string positionalArgument (int index) const
 

Detailed Description

A class for representing command-line arguments.

An Arguments object takes a LongOptions instance and uses it to parse the command-line arguments, as given by argc and argv. The class uses getopt_long() to parse the command-line arguments.

The optional and positional arguments can then be accessed with the methods optionalArgument() and positionalArgument(), respectively.

Definition at line 20 of file Arguments.h.

Constructor & Destructor Documentation

◆ Arguments()

Arguments::Arguments ( const LongOptions long_options,
int  argc,
char *  argv[] 
)

Construct from LongOptions instance, argc and argv.

The constructor uses getopt_long() internally, starting from the current value of optind. After construction, the value of optind is equal to argc.

Parameters
long_optionsinstance of LongOptions to determine valid options.
argcnumber of command-line arguments.
argvarray of command-line arguments.

Definition at line 9 of file Arguments.cc.

◆ ~Arguments()

Arguments::~Arguments ( )
default

Default destructor does nothing.

Member Function Documentation

◆ isOptionalArgumentSet()

bool Arguments::isOptionalArgumentSet ( const std::string &  option_name) const

Check whether optional argument was set.

Parameters
option_namename of optional argument.
Returns
whether optional argument was set.

Definition at line 38 of file Arguments.cc.

◆ numberOfPositionalArguments()

int Arguments::numberOfPositionalArguments ( ) const
Returns
number of positional arguments.

Definition at line 51 of file Arguments.cc.

◆ optionalArgument()

std::string Arguments::optionalArgument ( const std::string &  option_name) const

Return value of optional argument.

Parameters
option_namename of optional argument.
Returns
value of optional argument. Empty string if optional argument was not set.

Definition at line 45 of file Arguments.cc.

◆ positionalArgument()

std::string Arguments::positionalArgument ( int  index) const

Get positional argument from index.

Parameters
indexindex of positional argument
Returns
positional argument at the given index.

Definition at line 57 of file Arguments.cc.


The documentation for this class was generated from the following files: