equal
deleted
inserted
replaced
39 void (*func)(void); |
39 void (*func)(void); |
40 const char *helpString; |
40 const char *helpString; |
41 const char *briefDesc; |
41 const char *briefDesc; |
42 |
42 |
43 int execute(void) const; |
43 int execute(void) const; |
44 void displayHelp(void) const; |
44 string getHelpString(void) const; |
45 }; |
45 }; |
46 |
46 |
47 /*****************************************************************************/ |
47 /*****************************************************************************/ |
48 |
48 |
49 #define DEFINE_EXTERN_COMMAND(name) \ |
49 #define DEFINE_EXTERN_COMMAND(name) \ |
249 { |
249 { |
250 try { |
250 try { |
251 func(); |
251 func(); |
252 } catch (InvalidUsageException &e) { |
252 } catch (InvalidUsageException &e) { |
253 cerr << e.what() << endl << endl; |
253 cerr << e.what() << endl << endl; |
254 displayHelp(); |
254 cerr << getHelpString(); |
255 return 1; |
255 return 1; |
256 } catch (CommandException &e) { |
256 } catch (CommandException &e) { |
257 cerr << e.what() << endl; |
257 cerr << e.what() << endl; |
258 return 1; |
258 return 1; |
259 } catch (MasterDeviceException &e) { |
259 } catch (MasterDeviceException &e) { |
264 return 0; |
264 return 0; |
265 } |
265 } |
266 |
266 |
267 /****************************************************************************/ |
267 /****************************************************************************/ |
268 |
268 |
269 void Command::displayHelp() const |
269 string Command::getHelpString() const |
270 { |
270 { |
271 cerr << binaryBaseName << " " << commandName << " " << helpString; |
271 stringstream help; |
|
272 help << binaryBaseName << " " << commandName << " " << helpString; |
|
273 return help.str(); |
272 } |
274 } |
273 |
275 |
274 /****************************************************************************/ |
276 /****************************************************************************/ |
275 |
277 |
276 bool substrMatch(const string &abb, const string &full) |
278 bool substrMatch(const string &abb, const string &full) |
340 commandName = cmd->name; |
342 commandName = cmd->name; |
341 if (!helpRequested) { |
343 if (!helpRequested) { |
342 masterDev.setIndex(masterIndex); |
344 masterDev.setIndex(masterIndex); |
343 retval = cmd->execute(); |
345 retval = cmd->execute(); |
344 } else { |
346 } else { |
345 cmd->displayHelp(); |
347 cout << cmd->getHelpString(); |
346 } |
348 } |
347 } else { |
349 } else { |
348 cerr << "Ambiguous command abbreviation! Matching:" << endl; |
350 cerr << "Ambiguous command abbreviation! Matching:" << endl; |
349 for (ci = commands.begin(); ci != commands.end(); ci++) { |
351 for (ci = commands.begin(); ci != commands.end(); ci++) { |
350 cerr << (*ci)->name << endl; |
352 cerr << (*ci)->name << endl; |