Program to test class tfxx::comdline::Commandline.
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;
129 if (cmdline.optset(0))
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): '" 146 << cmdline.string_arg(iopt) <<
"'" << endl;
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): '" 154 << cmdline.double_arg(iopt) <<
"'" << endl;
155 cout <<
" argument (bool): '";
156 if (cmdline.bool_arg(iopt))
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;
180 if (!cmdline.optset(6))
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;
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
std::list< Filename > Tparsed
list to hold file names with options ,A tutorial is available in the detailed description of the Inte...
Namespace containing all components of module commandline. ,.
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: ...
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 ...
#define COMMANDLINETEST_VERSION