11#include " wsjcpp_arguments.h"
22#include < wsjcpp_core.h>
33
4+ // ---------------------------------------------------------------------
5+ // WsjcppArgumentSingle
6+
47WsjcppArgumentSingle::WsjcppArgumentSingle (const std::string &sName , const std::string &sDescription ) {
58 TAG = " WsjcppArgumentSingle-" + sName ;
69 m_sName = sName ;
@@ -20,6 +23,7 @@ std::string WsjcppArgumentSingle::getDescription() {
2023}
2124
2225// ---------------------------------------------------------------------
26+ // WsjcppArgumentParameter
2327
2428WsjcppArgumentParameter::WsjcppArgumentParameter (
2529 const std::string &sName ,
@@ -63,6 +67,7 @@ void WsjcppArgumentParameter::setValue(const std::string &sValue) {
6367}
6468
6569// ---------------------------------------------------------------------
70+ // WsjcppArgumentProcessor
6671
6772WsjcppArgumentProcessor::WsjcppArgumentProcessor (
6873 const std::vector<std::string> &vNames,
@@ -333,18 +338,19 @@ bool WsjcppArgumentProcessor::applySingleArgument(const std::string &sProgramNam
333338// ---------------------------------------------------------------------
334339
335340bool 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 () + " '" );
337342 return false ;
338343}
339344
340345// ---------------------------------------------------------------------
341346
342347int 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 ;
345350}
346351
347352// ---------------------------------------------------------------------
353+ // WsjcppArguments
348354
349355WsjcppArguments::WsjcppArguments (int argc, const char * argv[], WsjcppArgumentProcessor *pRoot) {
350356 TAG = " WsjcppArguments" ;
@@ -354,12 +360,21 @@ WsjcppArguments::WsjcppArguments(int argc, const char* argv[], WsjcppArgumentPro
354360 m_sProgramName = m_vArguments[0 ];
355361 m_vArguments.erase (m_vArguments.begin ());
356362 m_pRoot = pRoot;
363+ m_bEnablePrintAutoHelp = true ;
357364}
358365
359366// ---------------------------------------------------------------------
360367
361368WsjcppArguments::~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;
363378}
364379
365380// ---------------------------------------------------------------------
@@ -416,8 +431,12 @@ int WsjcppArguments::recursiveExec(
416431 if (vSubArguments.size () > 0 && vSubArguments[0 ] == " help" ) {
417432 return pArgumentProcessor->help (vRoutes, vSubArguments);
418433 }
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;
421440}
422441
423442// ---------------------------------------------------------------------
0 commit comments