Skip to content

Commit 931ed6a

Browse files
authored
Merge pull request #3 from wsjcpp/version-0.1.1
Fixed #2: added auto help
2 parents 2357aec + ae5ef92 commit 931ed6a

12 files changed

+264
-131
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ArgumentProcessorMain::ArgumentProcessorMain()
5151
: WsjcppArgumentProcessor("test_program", "TODO description") {
5252
TAG = "ArgumentProcessorMain";
5353
// registrySingleArgument("--single", "What exactly do this single param?");
54-
// registryParameterArgument("-param", "What need this param?");
54+
// registryParameterArgument("-param", "N", "What need this param?");
5555
// registryExample("here example of command");
5656
// registryProcessor(new ArgumentProcessorOtherProcessor());
5757
}
@@ -76,7 +76,10 @@ bool ArgumentProcessorMain::applyParameterArgument(
7676
7777
// ---------------------------------------------------------------------
7878
79-
int ArgumentProcessorMain::exec(const std::string &sProgramName, const std::vector<std::string> &vSubParams) {
79+
int ArgumentProcessorMain::exec(
80+
const std::vector<std::string> &vRoutes,
81+
const std::vector<std::string> &vSubParams
82+
) {
8083
WsjcppLog::err(TAG, "Not implemented");
8184
return -1;
8285
}

scripts.wsjcpp/generate.WsjcppArgumentProcessor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class " class_name " : public WsjcppArgumentProcessor {
4242

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

4848
#endif // " ifndef_header
@@ -60,7 +60,7 @@ concat content_source "
6060
: WsjcppArgumentProcessor({\"" argument_processor_name "\"}, \"TODO description\") {
6161
TAG = \"" class_name "\";
6262
// registrySingleArgument(\"--single\", \"What exactly do this single param?\");
63-
// registryParameterArgument(\"-param\", \"What need this param?\");
63+
// registryParameterArgument(\"-param\", \"N\", \"What need this param?\");
6464
// registryExample(\"here example of command\");
6565
// registryProcessor(new ArgumentProcessorOtherProcessor());
6666
}
@@ -85,7 +85,7 @@ bool " class_name "::applyParameterArgument(
8585

8686
// ---------------------------------------------------------------------
8787

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

src.wsjcpp/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Automaticly generated by wsjcpp@v0.0.1
1+
# Automaticly generated by wsjcpp@v0.1.5
22
cmake_minimum_required(VERSION 3.0)
33

4-
add_definitions(-DWSJCPP_VERSION="v0.0.1")
5-
add_definitions(-DWSJCPP_NAME="wsjcpp/wsjcpp-arguments")
4+
add_definitions(-DWSJCPP_APP_VERSION="v0.2.0")
5+
add_definitions(-DWSJCPP_APP_NAME="wsjcpp-arguments")
66

77
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
88
set(MACOSX TRUE)

src/ArgumentProcessors/argument_processor_main.cpp

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
// ArgumentProcessorMain
77

88
ArgumentProcessorMain::ArgumentProcessorMain()
9-
: WsjcppArgumentProcessor({"main"}, "Examples") {
9+
: WsjcppArgumentProcessor({"main"}, "Short description", "Here long description.") {
1010
TAG = "ArgumentProcessorMain";
1111
registrySingleArgument("--single1", "Single 1");
1212
registrySingleArgument("--single2", "Single 2");
13-
registryParameterArgument("-param1", "Param 1");
14-
registryParameterArgument("-param2", "Param 2");
13+
registryParameterArgument("-param1", "P", "Param 1");
14+
registryParameterArgument("-param2", "P", "Param 2");
1515
registryExample("wsjcpp --single1 -param1 1");
16-
// registryProcessor(new ArgumentProcessorOtherProcessor());
16+
registryProcessor(new ArgumentProcessorSubcommand1());
1717
}
1818

1919
// ---------------------------------------------------------------------
@@ -36,8 +36,64 @@ bool ArgumentProcessorMain::applyParameterArgument(
3636

3737
// ---------------------------------------------------------------------
3838

39-
int ArgumentProcessorMain::exec(const std::string &sProgramName, const std::vector<std::string> &vSubParams) {
39+
int ArgumentProcessorMain::exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams) {
4040
WsjcppLog::err(TAG, "Not implemented");
4141
return -1;
4242
}
4343

44+
45+
// ---------------------------------------------------------------------
46+
// ArgumentProcessorSubcommand1
47+
48+
ArgumentProcessorSubcommand1::ArgumentProcessorSubcommand1()
49+
: WsjcppArgumentProcessor(
50+
{"subcommand1", "sc1"},
51+
"Subcommand1",
52+
"Example of subcommand1 with long description must be here 12345678901234567890 lol"
53+
) {
54+
TAG = "ArgumentProcessorSubcommand1";
55+
registrySingleArgument("--silent", "Silent mode. Will be print 'silent' - no more.");
56+
registrySingleArgument("--first", "First. Will be print 'first' - no more.");
57+
registryParameterArgument("-times", "N", "How much times print line 'test'");
58+
59+
m_bSilent = false;
60+
m_bFirst = false;
61+
m_nTimesTest = 0;
62+
}
63+
64+
// ---------------------------------------------------------------------
65+
66+
bool ArgumentProcessorSubcommand1::applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName) {
67+
if (sArgumentName == "--silent") {
68+
m_bSilent = true;
69+
return true;
70+
}
71+
72+
if (sArgumentName == "--first") {
73+
m_bFirst = true;
74+
return true;
75+
}
76+
77+
return false;
78+
}
79+
80+
// ---------------------------------------------------------------------
81+
82+
bool ArgumentProcessorSubcommand1::applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue) {
83+
if (sArgumentName == "-times") {
84+
m_nTimesTest = std::atoi(sValue.c_str());
85+
return true;
86+
}
87+
return false;
88+
}
89+
90+
// ---------------------------------------------------------------------
91+
92+
int ArgumentProcessorSubcommand1::exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams) {
93+
WsjcppLog::info(TAG, "Exec");
94+
for (int i = 0; i < m_nTimesTest; i++) {
95+
std::cout << i << ": test" << std::endl;
96+
}
97+
return 0;
98+
}
99+

src/ArgumentProcessors/argument_processor_main.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,23 @@ class ArgumentProcessorMain : public WsjcppArgumentProcessor {
77
public:
88
ArgumentProcessorMain();
99

10+
11+
virtual bool applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName);
1012
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);
14+
};
15+
16+
class ArgumentProcessorSubcommand1 : public WsjcppArgumentProcessor {
17+
public:
18+
ArgumentProcessorSubcommand1();
1119
virtual bool applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName);
12-
virtual int exec(const std::string &sProgramName, const std::vector<std::string> &vSubParams);
20+
virtual bool applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue);
21+
virtual int exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams);
22+
23+
private:
24+
bool m_bSilent;
25+
bool m_bFirst;
26+
int m_nTimesTest;
1327
};
1428

1529
#endif // ARGUMENT_PROCESSOR_MAIN_H

src/main.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
int main(int argc, const char* argv[]) {
88
std::string TAG = "MAIN";
9-
std::string appName = std::string(WSJCPP_NAME);
10-
std::string appVersion = std::string(WSJCPP_VERSION);
9+
std::string appName = std::string(WSJCPP_APP_NAME);
10+
std::string appVersion = std::string(WSJCPP_APP_VERSION);
1111

1212
std::string appLogPath = ".logs";
1313
if (!WsjcppCore::dirExists(appLogPath)) {
@@ -21,9 +21,7 @@ int main(int argc, const char* argv[]) {
2121

2222
int nResult = prog.exec();
2323
if (nResult != 0) {
24-
// print help
2524
std::cout << "Try exec help" << std::endl;
26-
std::cout << prog.help();
2725
}
2826
return nResult;
2927
}

0 commit comments

Comments
 (0)