34 #define COMMANDLINETEST_VERSION \ 35 "COMMANDLINETEST V1.0 test commandline class" 38 #include <tfxx/commandline.h> 39 #include <tfxx/xcmdline.h> 54 int main(
int iargc,
char* argv[])
61 "usage: commandlinetest argument [-v] [-o n] [-f name] [-q [r]]" "\n" 62 " [-longopt f] [-F] [value [value ...]]" "\n" 63 " or: commandlinetest --help|-h" "\n" 69 "argument one argument is mandatory" "\n" 70 "value additional arguments (optional)" "\n" 73 "-v set a flag (no argument is allowed)" "\n" 74 "-o n set an integer value (argument mandatory)" "\n" 75 "-f name set a string value (argument mandatory)" "\n" 76 "-q r set an integer value (argument optional)" "\n" 77 "-longopt f set the value for a long option name" "\n" 78 "-F evaluate file name options" "\n" 79 " availabe keys are: \"f\", \"dl\", \"k\"" "\n" 81 "Long options may be abbreviated - test it!" "\n" 83 "Notice that you have to use the syntax" "\n" 87 "with the optional argument for option -q. This syntax" "\n" 88 "is mandatory with optional arguments, but may also be used" "\n" 89 "with mandatory arguments." "\n" 116 static const char* keys[]={
"f",
"dl",
"k", 0};
121 cerr << usage_text << endl;
131 cerr << usage_text << endl;
132 cerr << help_text << endl;
136 cout <<
"Here I tell you about the options you supplied:" << endl;
138 for (
int iopt=0; iopt<6; iopt++)
141 cout <<
"option: '" << options[iopt].
opt_string <<
"'" << endl;
142 if (cmdline.
optset(iopt)) { cout <<
" option was set"; }
143 else { cout <<
" option was not set"; }
145 cout <<
" argument (string): '" 147 cout <<
" argument (int): '" 148 << cmdline.
int_arg(iopt) <<
"'" << endl;
149 cout <<
" argument (long): '" 150 << cmdline.
long_arg(iopt) <<
"'" << endl;
151 cout <<
" argument (float): '" 152 << cmdline.
float_arg(iopt) <<
"'" << endl;
153 cout <<
" argument (double): '" 155 cout <<
" argument (bool): '";
157 { cout <<
"true"; }
else { cout <<
"false"; }
163 cout <<
"evaluating your choice:" << endl;
164 cout <<
" verbose mode switched ";
165 if (cmdline.
optset(1)) { cout <<
"ON"; }
else { cout <<
"OFF"; }
167 if (cmdline.
optset(2)) { cout <<
" set:"; }
168 else { cout <<
" default:"; }
169 cout <<
" -o: '" << cmdline.
int_arg(2) <<
"'" << endl;
170 if (cmdline.
optset(3)) { cout <<
" set:"; }
171 else { cout <<
" default:"; }
172 cout <<
" -f: '" << cmdline.
string_arg(3) <<
"'" << endl;
173 if (cmdline.
optset(4)) { cout <<
" set:"; }
174 else { cout <<
" default:"; }
175 cout <<
" -q: '" << cmdline.
float_arg(4) <<
"'" << endl;
176 if (cmdline.
optset(5)) { cout <<
" set:"; }
177 else { cout <<
" default:"; }
178 cout <<
" -longopt: '" << cmdline.
string_arg(5) <<
"'" << endl;
184 cout <<
"And here is the rest of your command line arguments:" << endl;
185 while (cmdline.
extra()) { cout << cmdline.
next() << endl; }
190 cout <<
"Parse file names and options" << endl;
191 cout <<
"Supported options keys are:" << endl;
192 const char** thekeys=keys;
193 const char* key=*thekeys;
196 std::cout <<
" next key is: \"" << key <<
"\"" << std::endl;
201 Tparsed::const_iterator i=result.begin();
202 while(i!=result.end())
204 std::cout <<
"filename: \"" << i->name <<
"\"" << std::endl;
205 Toptionmap::const_iterator j=i->options.begin();
206 while(j!=i->options.end())
208 std::cout <<
" " << j->first
209 <<
" \"" << j->second <<
"\"" << std::endl;
212 const char ** k=keys;
217 std::cout <<
" key " << *k <<
": found " << i->count(*k)
218 <<
" entries" << std::endl;
219 std::cout <<
" first entry is \"" << i->value(*k) <<
222 std::cout <<
" all entries are:" << std::endl;
223 Toptionmap::const_iterator p=e.begin();
226 std::cout <<
" \"" << p->second <<
"\"" << std::endl;
int int_arg(const int &iopt) const
return argument of option # iopt as int value
const char * opt_string
option name
Tparsed parse_cmdline(tfxx::cmdline::Commandline &c, const char **keys, const bool &debug)
parse command line arguments for file names and options ,A tutorial is available in the detailed desc...
option requires an argument
bool optset(const int &iopt) const
true if option # iopt was set on commandline
std::list< Filename > Tparsed
list to hold file names with options ,A tutorial is available in the detailed description of the Inte...
double double_arg(const int &iopt) const
return argument of option # iopt as double value
int main(int iargc, char *argv[])
Program to test class tfxx::comdline::Commandline.
bool bool_arg(const int &iopt) const
return argument of option # iopt as bool value
long long_arg(const int &iopt) const
return argument of option # iopt as long value
char * next()
returns char-array of next commandline argument
Namespace containing all components of module commandline. ,.
bool extra() const
true if there are more commandline arguments
Evaluates commandline by calling long_getopt. ,You may instantiate a Commandline object by passing th...
option may have an optional argument
struct to define options ,This struct is used to define a list of options. An example is: ...
float float_arg(const int &iopt) const
return argument of option # iopt as float value
std::multimap< std::string, std::string > Toptionmap
map to hold file options ,A std::multimap is an STL container of pairs. It provides STL iterators to ...
std::string string_arg(const int &iopt) const
return argument of option # iopt as string value
#define COMMANDLINETEST_VERSION