1
1
#include " wsjcpp_arguments.h"
2
2
#include < wsjcpp_core.h>
3
3
4
+ // ---------------------------------------------------------------------
5
+ // WsjcppArgumentSingle
6
+
4
7
WsjcppArgumentSingle::WsjcppArgumentSingle (const std::string &sName , const std::string &sDescription ) {
5
8
TAG = " WsjcppArgumentSingle-" + sName ;
6
9
m_sName = sName ;
@@ -20,6 +23,7 @@ std::string WsjcppArgumentSingle::getDescription() {
20
23
}
21
24
22
25
// ---------------------------------------------------------------------
26
+ // WsjcppArgumentParameter
23
27
24
28
WsjcppArgumentParameter::WsjcppArgumentParameter (
25
29
const std::string &sName ,
@@ -63,6 +67,7 @@ void WsjcppArgumentParameter::setValue(const std::string &sValue) {
63
67
}
64
68
65
69
// ---------------------------------------------------------------------
70
+ // WsjcppArgumentProcessor
66
71
67
72
WsjcppArgumentProcessor::WsjcppArgumentProcessor (
68
73
const std::vector<std::string> &vNames,
@@ -333,18 +338,19 @@ bool WsjcppArgumentProcessor::applySingleArgument(const std::string &sProgramNam
333
338
// ---------------------------------------------------------------------
334
339
335
340
bool WsjcppArgumentProcessor::applyParameterArgument (const std::string &sProgramName , const std::string &sArgumentName , const std::string &sValue ) {
336
- WsjcppLog::throw_err (TAG, " No support parameter argument '" + sArgumentName + " ' for '" + getNamesAsString () + " '" );
341
+ WsjcppLog::err (TAG, " No support parameter argument '" + sArgumentName + " ' for '" + getNamesAsString () + " '" );
337
342
return false ;
338
343
}
339
344
340
345
// ---------------------------------------------------------------------
341
346
342
347
int WsjcppArgumentProcessor::exec (const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams) {
343
- WsjcppLog::throw_err (TAG, " Processor '" + getNamesAsString () + " ' has not implementation" );
344
- return -1 ;
348
+ WsjcppLog::err (TAG, " Processor '" + getNamesAsString () + " ' has not implementation" );
349
+ return -10 ;
345
350
}
346
351
347
352
// ---------------------------------------------------------------------
353
+ // WsjcppArguments
348
354
349
355
WsjcppArguments::WsjcppArguments (int argc, const char * argv[], WsjcppArgumentProcessor *pRoot) {
350
356
TAG = " WsjcppArguments" ;
@@ -354,12 +360,21 @@ WsjcppArguments::WsjcppArguments(int argc, const char* argv[], WsjcppArgumentPro
354
360
m_sProgramName = m_vArguments[0 ];
355
361
m_vArguments.erase (m_vArguments.begin ());
356
362
m_pRoot = pRoot;
363
+ m_bEnablePrintAutoHelp = true ;
357
364
}
358
365
359
366
// ---------------------------------------------------------------------
360
367
361
368
WsjcppArguments::~WsjcppArguments () {
362
- // TODO
369
+ for (int i = 0 ; i < m_vProcessors.size (); i++) {
370
+ delete m_vProcessors[i];
371
+ }
372
+ }
373
+
374
+ // ---------------------------------------------------------------------
375
+
376
+ void WsjcppArguments::enablePrintAutoHelp (bool bEnablePrintAutoHelp) {
377
+ m_bEnablePrintAutoHelp = bEnablePrintAutoHelp;
363
378
}
364
379
365
380
// ---------------------------------------------------------------------
@@ -416,8 +431,12 @@ int WsjcppArguments::recursiveExec(
416
431
if (vSubArguments.size () > 0 && vSubArguments[0 ] == " help" ) {
417
432
return pArgumentProcessor->help (vRoutes, vSubArguments);
418
433
}
419
-
420
- return pArgumentProcessor->exec (vRoutes, vSubArguments);
434
+
435
+ int nResult = pArgumentProcessor->exec (vRoutes, vSubArguments);
436
+ if (nResult == -10 && m_bEnablePrintAutoHelp) {
437
+ pArgumentProcessor->help (vRoutes, vSubArguments);
438
+ }
439
+ return nResult;
421
440
}
422
441
423
442
// ---------------------------------------------------------------------
0 commit comments