Manages arguments passed to a program (i.e., main(argc, argv) parameters). More...

#include <CommandLine.h>

Collaboration diagram for CommandLine:

Public Types

typedef void Visitor(const int optId, const char *optValue)

Public Member Functions

 CommandLine (int argc, char *argv[], const char *shortRules, const RawLongOption *longRules)
 expects main() input plus getopt_long(3) grammar rules for parsing argv More...
 CommandLine (const CommandLine &them)
 ~CommandLine ()
CommandLineoperator= (const CommandLine &)
bool hasOption (const int optId, const char **optValue=nullptr) const
void forEachOption (Visitor) const
 calls Visitor for each of the configured command line option More...
const char * arg0 () const
int argc () const
char ** argv () const
void resetArg0 (const char *programName)
 replaces argv[0] with the new value More...
void pushFrontOption (const char *name, const char *value=nullptr)
 inserts a (possibly duplicated) option at the beginning of options (just after argv[0]) More...

Private Member Functions

const RawLongOptionlongOptions () const
bool nextOption (int &optId) const

Private Attributes

std::vector< char * > argv_
 raw main() parameters, including argv[0] and a nil argv[argc] More...
const char * shortOptions_
 single-dash, single-letter (-x) option rules More...
std::vector< LongOptionlongOptions_
 long –option rules More...

Detailed Description

Definition at line 34 of file CommandLine.h.

Member Typedef Documentation

◆ Visitor

typedef void CommandLine::Visitor(const int optId, const char *optValue)

A callback function for forEachOption(); receives parsed options. Must not call pushFrontOption(), hasOption() or forEachOption() – getopt(3) uses globals!

Definition at line 52 of file CommandLine.h.

Constructor & Destructor Documentation

◆ CommandLine() [1/2]

CommandLine::CommandLine ( int  argc,
char *  argv[],
const char *  shortRules,
const RawLongOption longRules 

Definition at line 24 of file

References argv_, assert, longOptions_, and xstrdup.

◆ CommandLine() [2/2]

CommandLine::CommandLine ( const CommandLine them)

Definition at line 46 of file

◆ ~CommandLine()

CommandLine::~CommandLine ( )

Definition at line 62 of file

References argv_, shortOptions_, and xfree.

Member Function Documentation

◆ arg0()

const char * CommandLine::arg0 ( ) const
argv[0], which is usually a program "name"

Definition at line 58 of file CommandLine.h.

References argv_.

Referenced by watch_child().

◆ argc()

int CommandLine::argc ( ) const
main()'s argc, which is traditionally missing the last/nil item

Definition at line 61 of file CommandLine.h.

References argv_.

Referenced by nextOption().

◆ argv()

char ** CommandLine::argv ( ) const
main()'s argv[] which is traditionally const-wrong

Definition at line 64 of file CommandLine.h.

References argv_.

Referenced by nextOption().

◆ forEachOption()

void CommandLine::forEachOption ( Visitor  visitor) const

Definition at line 89 of file

References nextOption(), optarg, and ResetGetopt().

Referenced by SquidMain().

◆ hasOption()

bool CommandLine::hasOption ( const int  optId,
const char **  optValue = nullptr 
) const
whether the option with optId identifier is present When returning true, sets non-nil optValue to the found option's value. For letter options (-x) and their –long synonyms, the letter is the ID. For long-only –options, the ID is the configured options::val value.

Definition at line 71 of file

References nextOption(), optarg, and ResetGetopt().

Referenced by ConfigureCurrentKid().

◆ longOptions()

const RawLongOption * CommandLine::longOptions ( ) const

Definition at line 73 of file CommandLine.h.

References longOptions_.

Referenced by nextOption().

◆ nextOption()

bool CommandLine::nextOption ( int optId) const

extracts the next option (if any)

whether the option was extracted throws on unknown option or missing required argument

Definition at line 101 of file

References argc(), argv(), argv_, assert, longOptions(), optind, SBuf::Printf(), shortOptions_, and TexcHere.

Referenced by forEachOption(), and hasOption().

◆ operator=()

CommandLine & CommandLine::operator= ( const CommandLine them)

Definition at line 52 of file

References argv_, longOptions_, and shortOptions_.

◆ pushFrontOption()

void CommandLine::pushFrontOption ( const char *  name,
const char *  value = nullptr 

Definition at line 123 of file

References argv_, assert, and xstrdup.

◆ resetArg0()

void CommandLine::resetArg0 ( const char *  programName)

Definition at line 115 of file

References argv_, assert, xfree, and xstrdup.

Referenced by watch_child().

Member Data Documentation

◆ argv_

std::vector<char *> CommandLine::argv_

◆ longOptions_

std::vector<LongOption> CommandLine::longOptions_

Definition at line 81 of file CommandLine.h.

Referenced by CommandLine(), longOptions(), and operator=().

◆ shortOptions_

const char* CommandLine::shortOptions_

Definition at line 80 of file CommandLine.h.

Referenced by ~CommandLine(), nextOption(), and operator=().

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






Web Site Translations