Skip to content

Commit 64b04e9

Browse files
committed
Fixed #4 added autohelp print
1 parent 5dd2374 commit 64b04e9

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed

scripts.wsjcpp/generate.WsjcppArgumentProcessor.wsjcpp-script

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ class " class_name " : public WsjcppArgumentProcessor {
4040
public:
4141
" class_name "();
4242

43-
virtual bool applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue);
44-
virtual bool applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName);
45-
virtual int exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams);
43+
virtual bool applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue) override;
44+
virtual bool applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName) override;
45+
virtual int exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams) override;
4646
};
4747

4848
#endif // " ifndef_header
@@ -87,7 +87,7 @@ bool " class_name "::applyParameterArgument(
8787

8888
int " class_name "::exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams) {
8989
WsjcppLog::err(TAG, \"Not implemented\");
90-
return -1;
90+
return -10;
9191
}
9292
"
9393

src/ArgumentProcessors/argument_processor_main.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ bool ArgumentProcessorMain::applyParameterArgument(
3535
return false;
3636
}
3737

38-
// ---------------------------------------------------------------------
39-
40-
int ArgumentProcessorMain::exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams) {
41-
WsjcppLog::err(TAG, "Not implemented");
42-
return -1;
43-
}
44-
4538
// ---------------------------------------------------------------------
4639
// ArgumentProcessorSubcommand1
4740

src/ArgumentProcessors/argument_processor_main.h

-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
class ArgumentProcessorMain : public WsjcppArgumentProcessor {
77
public:
88
ArgumentProcessorMain();
9-
10-
119
virtual bool applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName);
1210
virtual bool applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue);
13-
virtual int exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams);
1411
};
1512

1613
class ArgumentProcessorSubcommand1 : public WsjcppArgumentProcessor {

src/wsjcpp_arguments.cpp

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "wsjcpp_arguments.h"
22
#include <wsjcpp_core.h>
33

4+
// ---------------------------------------------------------------------
5+
// WsjcppArgumentSingle
6+
47
WsjcppArgumentSingle::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

2428
WsjcppArgumentParameter::WsjcppArgumentParameter(
2529
const std::string &sName,
@@ -63,6 +67,7 @@ void WsjcppArgumentParameter::setValue(const std::string &sValue) {
6367
}
6468

6569
// ---------------------------------------------------------------------
70+
// WsjcppArgumentProcessor
6671

6772
WsjcppArgumentProcessor::WsjcppArgumentProcessor(
6873
const std::vector<std::string> &vNames,
@@ -333,18 +338,19 @@ bool WsjcppArgumentProcessor::applySingleArgument(const std::string &sProgramNam
333338
// ---------------------------------------------------------------------
334339

335340
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() + "'");
337342
return false;
338343
}
339344

340345
// ---------------------------------------------------------------------
341346

342347
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;
345350
}
346351

347352
// ---------------------------------------------------------------------
353+
// WsjcppArguments
348354

349355
WsjcppArguments::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

361368
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;
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
// ---------------------------------------------------------------------

src/wsjcpp_arguments.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class WsjcppArgumentProcessor {
7474
const std::vector<std::string> &vSubParams
7575
);
7676
bool hasMoreOptions();
77-
77+
7878
virtual bool applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName);
7979
virtual bool applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue);
8080
virtual int exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams);
@@ -113,6 +113,7 @@ class WsjcppArguments {
113113
public:
114114
WsjcppArguments(int argc, const char* argv[], WsjcppArgumentProcessor *pRoot);
115115
~WsjcppArguments();
116+
void enablePrintAutoHelp(bool bEnablePrintAutoHelp);
116117
int exec();
117118

118119
private:
@@ -132,7 +133,9 @@ class WsjcppArguments {
132133
std::string TAG;
133134
std::vector<std::string> m_vArguments;
134135
std::string m_sProgramName;
136+
bool m_bEnablePrintAutoHelp;
135137
std::vector<WsjcppArgumentProcessor *> m_vProcessors;
138+
136139
};
137140

138141
// ---------------------------------------------------------------------

0 commit comments

Comments
 (0)