Simple test program for GetOpt. Binary should be installed as ui-utilcpp-getopt.
#include "config.h"
#include <iostream>
int main(int argc, char *argv[])
{
int retValue(0);
getOpt
.
set(
"version",
'v', UI::Util::GetOpt::NoArg_,
"Show version information.")
.
set(
"help",
'h', UI::Util::GetOpt::NoArg_,
"Show usage information.")
.
set(
"noarg",
'n', UI::Util::GetOpt::NoArg_,
"Option with no argument.")
.
set(
"arg",
'a', UI::Util::GetOpt::Arg_,
"Option with mandatory argument.")
.
set(
"optarg",
'o', UI::Util::GetOpt::OptArg_,
"Option with optional argument.");
{
}
{
std::cout << "Release: " << PACKAGE << "-" << VERSION << "." << std::endl << std::endl;
}
{
std::cout << std::endl << "Blah tool to do blah." << std::endl;
}
else
{
{
std::cout << "Option \"noarg\" given." << std::endl;
}
{
std::cout << "Option \"arg\" given." << std::endl;
std::cout <<
"Argument is: " << getOpt.
get(
"arg")->
getArg() << std::endl;
}
{
std::cout << "Option \"arg\" given." << std::endl;
std::cout <<
"Argument is: " << getOpt.
get(
"optarg")->
getArg() << std::endl;
}
std::cout << "Program Main Run" << std::endl;
std::cout << "Try --help if you want to test GetOpt" << std::endl;
}
return retValue;
}
Abstraction of GNU C "getopt_long(3)".
bool isGiven() const
Check if this option was given.
Definition GetOpt.cpp:48
std::string getArg() const
Get argument given with this option.
Definition GetOpt.cpp:53
Abstraction class for GNU getopt_long(3).
Definition GetOpt.hpp:171
GetOpt & set(std::string const &nameLong, char nameShort, Type type, std::string const &doc="No documentation for this option.", std::string const &defaultArg="")
Introduce a new option.
Definition GetOpt.cpp:174
CLOption * get(char nameShort)
Get an option object from short name.
Definition GetOpt.cpp:196
int wrongUsage(std::string const &reason, std::string const &title="\nUsage:\n\n") const
Helper.
Definition GetOpt.cpp:293
bool isValid()
Check if given command line arguments are "well-formed".
Definition GetOpt.cpp:284
void printUsage(std::string const &title="\nUsage:\n\n") const
Prints out Usage information to cout (stdout).
Definition GetOpt.cpp:300