Skip to content

Commit 722d321

Browse files
authored
Merge pull request #7 from wsjcpp/version-0.2.2
Version 0.2.2
2 parents 34530fd + 64b04e9 commit 722d321

14 files changed

+115
-78
lines changed

Diff for: scripts.wsjcpp/generate.WsjcppArgumentProcessor renamed to 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

Diff for: src.wsjcpp/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Automaticly generated by wsjcpp@v0.1.6
1+
# Automaticly generated by wsjcpp@v0.2.0
22
cmake_minimum_required(VERSION 3.0)
33

44
add_definitions(-DWSJCPP_APP_VERSION="v0.2.1")

Diff for: src.wsjcpp/wsjcpp_core/wsjcpp.hold.yml

+7
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,31 @@ distribution:
2121
- source-file: src/wsjcpp_core.cpp
2222
target-file: wsjcpp_core.cpp
2323
type: "source-code"
24+
sha1: "09ef821bbc090fc1cd8a15bc4a57a9a2ce8ae00d"
2425
- source-file: src/wsjcpp_core.h
2526
target-file: wsjcpp_core.h
2627
type: "source-code" # todo must be header-file
28+
sha1: "e6e4ab2067d3c942db08e3b79862486eaf851e4b"
2729
- source-file: "src/wsjcpp_unit_tests.cpp"
2830
target-file: "wsjcpp_unit_tests.cpp"
2931
type: "unit-tests"
32+
sha1: "fd5989d1a83c8b90bdc4d5e9bc9c3051eaa1e6d2"
3033
- source-file: "src/wsjcpp_unit_tests.h"
3134
target-file: "wsjcpp_unit_tests.h"
3235
type: "unit-tests"
36+
sha1: "83d4b6e046b6b58c42882ccae4be413e03c401c1"
3337
- source-file: "src/wsjcpp_unit_tests_main.cpp"
3438
target-file: "wsjcpp_unit_tests_main.cpp"
3539
type: "unit-tests"
40+
sha1: "388ae269b325c5e161f6c3a5c598575714a4bffc"
3641
- source-file: "scripts.wsjcpp/generate.WsjcppUnitTest.wsjcpp-script"
3742
target-file: "generate.WsjcppUnitTest.wsjcpp-script"
3843
type: "safe-scripting-generate"
44+
sha1: "a7c9c2d19bf81c5b00e659384b0b92a99319a4c1"
3945
- source-file: "scripts.wsjcpp/generate.Class.wsjcpp-script"
4046
target-file: "generate.Class.wsjcpp-script"
4147
type: "safe-scripting-generate"
48+
sha1: "de1799907c685d606b93e08b821b540c2faa2db1"
4249

4350
unit-tests:
4451
cases:

Diff for: src/ArgumentProcessors/argument_processor_main.cpp

+19-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ArgumentProcessorMain::ArgumentProcessorMain()
1414
registryParameterArgument("-param2", "P", "Param 2");
1515
registryExample("wsjcpp --single1 -param1 1");
1616
registryProcessor(new ArgumentProcessorSubcommand1());
17+
registryProcessor(new ArgumentProcessorNothing());
1718
}
1819

1920
// ---------------------------------------------------------------------
@@ -34,14 +35,6 @@ bool ArgumentProcessorMain::applyParameterArgument(
3435
return false;
3536
}
3637

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

@@ -97,3 +90,21 @@ int ArgumentProcessorSubcommand1::exec(const std::vector<std::string> &vRoutes,
9790
return 0;
9891
}
9992

93+
// ---------------------------------------------------------------------
94+
// ArgumentProcessorNothing
95+
96+
ArgumentProcessorNothing::ArgumentProcessorNothing()
97+
: WsjcppArgumentProcessor(
98+
{"nothing", "n"},
99+
"nothing",
100+
"Example of nothing with long description must be here 12345678901234567890 lol again"
101+
) {
102+
TAG = "ArgumentProcessorSubcommand1";
103+
}
104+
105+
// ---------------------------------------------------------------------
106+
107+
int ArgumentProcessorNothing::exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams) {
108+
std::cout << "Nothing" << std::endl;
109+
return 0;
110+
}

Diff for: src/ArgumentProcessors/argument_processor_main.h

+6-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 {
@@ -26,4 +23,10 @@ class ArgumentProcessorSubcommand1 : public WsjcppArgumentProcessor {
2623
int m_nTimesTest;
2724
};
2825

26+
class ArgumentProcessorNothing : public WsjcppArgumentProcessor {
27+
public:
28+
ArgumentProcessorNothing();
29+
virtual int exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams) override;
30+
};
31+
2932
#endif // ARGUMENT_PROCESSOR_MAIN_H

Diff for: src/wsjcpp_arguments.cpp

+50-13
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,
@@ -293,20 +298,38 @@ int WsjcppArgumentProcessor::help(
293298

294299
for (int i = 0; i < m_vProcessors.size(); i++) {
295300
WsjcppArgumentProcessor *pProc = m_vProcessors[i];
296-
297-
std::cout
298-
<< " " << pProc->getNamesAsString() << " [<options>...]"
299-
<< std::endl
300-
<< " Subcommand. Try help for more. " << pProc->getDescription()
301-
<< std::endl
302-
<< std::endl;
301+
std::cout << " " << pProc->getNamesAsString();
302+
303+
if (pProc->hasMoreOptions()) {
304+
std::cout
305+
<< " [<options>...]"
306+
<< std::endl
307+
<< " Subcommand. Try help for more. " << pProc->getDescription()
308+
<< std::endl
309+
;
310+
} else {
311+
std::cout
312+
<< std::endl
313+
<< " " << pProc->getDescription()
314+
<< std::endl
315+
;
316+
}
317+
std::cout << std::endl;
303318
}
304319
}
305320
return 0;
306321
}
307322

308323
// ---------------------------------------------------------------------
309324

325+
bool WsjcppArgumentProcessor::hasMoreOptions() {
326+
return m_vProcessors.size() > 0
327+
|| m_vSingleArguments.size() > 0
328+
|| m_vParameterArguments.size() > 0;
329+
}
330+
331+
// ---------------------------------------------------------------------
332+
310333
bool WsjcppArgumentProcessor::applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName) {
311334
WsjcppLog::throw_err(TAG, "No support single argument '" + sArgumentName + "'");
312335
return false;
@@ -315,18 +338,19 @@ bool WsjcppArgumentProcessor::applySingleArgument(const std::string &sProgramNam
315338
// ---------------------------------------------------------------------
316339

317340
bool WsjcppArgumentProcessor::applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue) {
318-
WsjcppLog::throw_err(TAG, "No support parameter argument '" + sArgumentName + "' for '" + getNamesAsString() + "'");
341+
WsjcppLog::err(TAG, "No support parameter argument '" + sArgumentName + "' for '" + getNamesAsString() + "'");
319342
return false;
320343
}
321344

322345
// ---------------------------------------------------------------------
323346

324347
int WsjcppArgumentProcessor::exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams) {
325-
WsjcppLog::throw_err(TAG, "Processor '" + getNamesAsString() + "' has not implementation");
326-
return -1;
348+
WsjcppLog::err(TAG, "Processor '" + getNamesAsString() + "' has not implementation");
349+
return -10;
327350
}
328351

329352
// ---------------------------------------------------------------------
353+
// WsjcppArguments
330354

331355
WsjcppArguments::WsjcppArguments(int argc, const char* argv[], WsjcppArgumentProcessor *pRoot) {
332356
TAG = "WsjcppArguments";
@@ -336,12 +360,21 @@ WsjcppArguments::WsjcppArguments(int argc, const char* argv[], WsjcppArgumentPro
336360
m_sProgramName = m_vArguments[0];
337361
m_vArguments.erase(m_vArguments.begin());
338362
m_pRoot = pRoot;
363+
m_bEnablePrintAutoHelp = true;
339364
}
340365

341366
// ---------------------------------------------------------------------
342367

343368
WsjcppArguments::~WsjcppArguments() {
344-
// 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;
345378
}
346379

347380
// ---------------------------------------------------------------------
@@ -398,8 +431,12 @@ int WsjcppArguments::recursiveExec(
398431
if (vSubArguments.size() > 0 && vSubArguments[0] == "help") {
399432
return pArgumentProcessor->help(vRoutes, vSubArguments);
400433
}
401-
402-
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;
403440
}
404441

405442
// ---------------------------------------------------------------------

Diff for: src/wsjcpp_arguments.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ class WsjcppArgumentProcessor {
6767
WsjcppArgumentParameter *findRegisteredParameterArgument(const std::string &sArgumentName);
6868

6969
bool hasRegisteredArgumentName(const std::string &sArgumentName);
70-
70+
7171
bool getValueOfParam(const std::string &sArgumentName);
7272
int help(
7373
const std::vector<std::string> &vRoutes,
7474
const std::vector<std::string> &vSubParams
7575
);
76+
bool hasMoreOptions();
7677

7778
virtual bool applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName);
7879
virtual bool applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue);
@@ -112,6 +113,7 @@ class WsjcppArguments {
112113
public:
113114
WsjcppArguments(int argc, const char* argv[], WsjcppArgumentProcessor *pRoot);
114115
~WsjcppArguments();
116+
void enablePrintAutoHelp(bool bEnablePrintAutoHelp);
115117
int exec();
116118

117119
private:
@@ -131,7 +133,9 @@ class WsjcppArguments {
131133
std::string TAG;
132134
std::vector<std::string> m_vArguments;
133135
std::string m_sProgramName;
136+
bool m_bEnablePrintAutoHelp;
134137
std::vector<WsjcppArgumentProcessor *> m_vProcessors;
138+
135139
};
136140

137141
// ---------------------------------------------------------------------

Diff for: unit-tests.wsjcpp/CMakeLists.txt

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Automaticly generated by wsjcpp@v0.1.6
1+
# Automaticly generated by wsjcpp@v0.2.0
22
cmake_minimum_required(VERSION 3.0)
33

44
project(unit-tests C CXX)
@@ -34,9 +34,7 @@ list (APPEND WSJCPP_SOURCES "../src/wsjcpp_arguments.h")
3434

3535
# unit-tests
3636
list (APPEND WSJCPP_INCLUDE_DIRS "src")
37-
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_arguments_with_params.h")
3837
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_arguments_with_params.cpp")
39-
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_simple_arguments.h")
4038
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_simple_arguments.cpp")
4139

4240
# required-libraries
@@ -51,11 +49,3 @@ add_executable ("unit-tests" ${WSJCPP_SOURCES})
5149

5250
target_link_libraries("unit-tests" -lpthread ${WSJCPP_LIBRARIES} )
5351

54-
install(
55-
TARGETS
56-
"unit-tests"
57-
RUNTIME DESTINATION
58-
/usr/bin
59-
)
60-
61-

Diff for: unit-tests.wsjcpp/build_simple.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
if [ ! -d tmp ]; then
4-
mkdir -p tmp
4+
mkdir -p tmp
55
fi
66

77
cd tmp

Diff for: unit-tests.wsjcpp/src/unit_test_arguments_with_params.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "unit_test_arguments_with_params.h"
1+
#include <wsjcpp_unit_tests.h>
22
#include <vector>
33
#include <wsjcpp_core.h>
44
#include <wsjcpp_arguments.h>
@@ -52,6 +52,15 @@ class ArgumentProcessorUninstall : public WsjcppArgumentProcessor {
5252
};
5353

5454
// ---------------------------------------------------------------------
55+
// UnitTestArgumentsWithParams
56+
57+
class UnitTestArgumentsWithParams : public WsjcppUnitTestBase {
58+
public:
59+
UnitTestArgumentsWithParams();
60+
virtual bool doBeforeTest() override;
61+
virtual void executeTest() override;
62+
virtual bool doAfterTest() override;
63+
};
5564

5665
REGISTRY_WSJCPP_UNIT_TEST(UnitTestArgumentsWithParams)
5766

Diff for: unit-tests.wsjcpp/src/unit_test_arguments_with_params.h

-16
This file was deleted.

Diff for: unit-tests.wsjcpp/src/unit_test_simple_arguments.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "unit_test_simple_arguments.h"
1+
#include <wsjcpp_unit_tests.h>
22
#include <vector>
33
#include <wsjcpp_core.h>
44
#include <wsjcpp_arguments.h>
@@ -171,6 +171,14 @@ int ArgumentProcessorProgram1::exec(const std::vector<std::string> &vRoutes, con
171171
// ---------------------------------------------------------------------
172172
// UnitTestSimpleArguments
173173

174+
class UnitTestSimpleArguments : public WsjcppUnitTestBase {
175+
public:
176+
UnitTestSimpleArguments();
177+
virtual bool doBeforeTest() override;
178+
virtual void executeTest() override;
179+
virtual bool doAfterTest() override;
180+
};
181+
174182
REGISTRY_WSJCPP_UNIT_TEST(UnitTestSimpleArguments)
175183

176184
UnitTestSimpleArguments::UnitTestSimpleArguments()

0 commit comments

Comments
 (0)