Skip to content

Commit a6a1b4e

Browse files
committed
Updated wsjcpp-core and added generate.WSJCppArgumentProcessor
1 parent 0ab6973 commit a6a1b4e

30 files changed

+763
-187
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
wsjcpp-arguments
22
tmp/*
33
.vscode/*
4-
.wsjcpp-logs/*
5-
.wsjcpp-cache/*
4+
.wsjcpp/*
5+
.logs/*
66

77
# Prerequisites
88
*.d

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ project(wsjcpp-arguments)
44

55
include(${CMAKE_CURRENT_SOURCE_DIR}/src.wsjcpp/CMakeLists.txt)
66

7+
#### BEGIN_WSJCPP_APPEND
8+
list (APPEND WSJCPP_SOURCES "./src/argument_processor_main.h")
9+
list (APPEND WSJCPP_SOURCES "./src/argument_processor_main.cpp")
10+
#### END_WSJCPP_APPEND
11+
712
set(CMAKE_CXX_STANDARD 11)
813
set(EXECUTABLE_OUTPUT_PATH ${wsjcpp-arguments_SOURCE_DIR})
914

@@ -28,3 +33,5 @@ install(
2833
RUNTIME DESTINATION
2934
/usr/bin
3035
)
36+
37+

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,87 @@ or specify version:
1515
wsjcpp install "https://github.com/wsjcpp/wsjcpp-arguments:v0.0.1"
1616
```
1717

18+
## Example usage
1819

20+
header `argument_processor_test_program.h`:
21+
```
22+
#ifndef ARGUMENT_PROCESSOR_MAIN_H
23+
#define ARGUMENT_PROCESSOR_MAIN_H
24+
25+
#include <wsjcpp_arguments.h>
26+
27+
class ArgumentProcessorMain : public WSJCppArgumentProcessor {
28+
public:
29+
ArgumentProcessorMain();
30+
31+
virtual bool applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue);
32+
virtual bool applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName);
33+
virtual int exec(const std::string &sProgramName, const std::vector<std::string> &vSubParams);
34+
};
35+
36+
#endif // ARGUMENT_PROCESSOR_MAIN_H
37+
```
38+
39+
source-code `argument_processor_main.cpp`:
40+
41+
```
42+
#include "argument_processor_main.h"
43+
#include <wsjcpp_core.h>
44+
45+
// ---------------------------------------------------------------------
46+
// ArgumentProcessorMain
47+
48+
ArgumentProcessorMain::ArgumentProcessorMain()
49+
: WSJCppArgumentProcessor("test_program", "TODO description") {
50+
TAG = "ArgumentProcessorMain";
51+
// registrySingleArgument("--single", "What exactly do this single param?");
52+
// registryParameterArgument("-param", "What need this param?");
53+
// registryExample("here example of command");
54+
// registryProcessor(new ArgumentProcessorOtherProcessor());
55+
}
56+
57+
// ---------------------------------------------------------------------
1958
59+
bool ArgumentProcessorMain::applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName) {
60+
WSJCppLog::err(TAG, "Not implemented");
61+
return false;
62+
}
63+
64+
// ---------------------------------------------------------------------
65+
66+
bool ArgumentProcessorMain::applyParameterArgument(
67+
const std::string &sProgramName,
68+
const std::string &sArgumentName,
69+
const std::string &sValue
70+
) {
71+
WSJCppLog::err(TAG, "Not implemented");
72+
return false;
73+
}
74+
75+
// ---------------------------------------------------------------------
76+
77+
int ArgumentProcessorMain::exec(const std::string &sProgramName, const std::vector<std::string> &vSubParams) {
78+
WSJCppLog::err(TAG, "Not implemented");
79+
return -1;
80+
}
81+
```
82+
83+
usage:
84+
```
85+
#include <wsjcpp_arguments.h>
86+
#include "argument_processor_main.h"
87+
88+
89+
int main() {
90+
ArgumentProcessorMain *pMain = new ArgumentProcessorMain();
91+
WSJCppArguments prog(argc, argv, pMain);
92+
93+
int nResult = prog.exec();
94+
if (nResult != 0) {
95+
// print help
96+
std::cout << "Try exec help" << std::endl;
97+
std::cout << prog.help();
98+
}
99+
return nResult;
100+
}
101+
```
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/wsjcpp-safe-scripting
2+
3+
# log_info rootdir
4+
# log_info script_filename
5+
6+
make_dir "src"
7+
8+
var argument_processor_name
9+
set_value argument_processor_name arg1
10+
normalize_class_name argument_processor_name
11+
convert_CamelCase_to_snake_case argument_processor_name argument_processor_name
12+
13+
var class_name
14+
concat class_name "ArgumentProcessor" arg1
15+
normalize_class_name class_name
16+
17+
var base_filename
18+
convert_CamelCase_to_snake_case class_name base_filename
19+
# log_info base_filename
20+
21+
var filename_cpp
22+
concat filename_cpp "./src/" base_filename ".cpp"
23+
24+
var filename_h
25+
concat filename_h "./src/" base_filename ".h"
26+
27+
var ifndef_header
28+
set_value ifndef_header base_filename
29+
concat ifndef_header "_H"
30+
31+
to_upper_case ifndef_header
32+
33+
var content_header
34+
concat content_header "#ifndef " ifndef_header "
35+
#define " ifndef_header "
36+
37+
#include <wsjcpp_arguments.h>
38+
39+
class " class_name " : public WSJCppArgumentProcessor {
40+
public:
41+
" class_name "();
42+
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::string &sProgramName, const std::vector<std::string> &vSubParams);
46+
};
47+
48+
#endif // " ifndef_header
49+
50+
51+
var content_source
52+
concat content_source "
53+
#include \"" base_filename ".h\"
54+
#include <wsjcpp_core.h>
55+
56+
// ---------------------------------------------------------------------
57+
// " class_name "
58+
59+
" class_name "::" class_name "()
60+
: WSJCppArgumentProcessor(\"" argument_processor_name "\", \"TODO description\") {
61+
TAG = \"" argument_processor_name "\";
62+
// registrySingleArgument(\"--single\", \"What exactly do this single param?\");
63+
// registryParameterArgument(\"-param\", \"What need this param?\");
64+
// registryExample(\"here example of command\");
65+
// registryProcessor(new ArgumentProcessorOtherProcessor());
66+
}
67+
68+
// ---------------------------------------------------------------------
69+
70+
bool " class_name "::applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName) {
71+
WSJCppLog::err(TAG, \"Not implemented\");
72+
return false;
73+
}
74+
75+
// ---------------------------------------------------------------------
76+
77+
bool " class_name "::applyParameterArgument(
78+
const std::string &sProgramName,
79+
const std::string &sArgumentName,
80+
const std::string &sValue
81+
) {
82+
WSJCppLog::err(TAG, \"Not implemented\");
83+
return false;
84+
}
85+
86+
// ---------------------------------------------------------------------
87+
88+
int " class_name "::exec(const std::string &sProgramName, const std::vector<std::string> &vSubParams) {
89+
WSJCppLog::err(TAG, \"Not implemented\");
90+
return -1;
91+
}
92+
"
93+
94+
var file_source
95+
concat file_source "src/" filename_cpp
96+
97+
write_file filename_h content_header
98+
write_file filename_cpp content_source
99+
100+
log_info "
101+
======
102+
Generated class:
103+
- " class_name "
104+
Generated files:
105+
- " filename_h "
106+
- " filename_cpp "
107+
======
108+
"
109+
110+
cmakelists_txt_append_wsjcpp filename_h
111+
cmakelists_txt_append_wsjcpp filename_cpp

src.wsjcpp/CMakeLists.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1-
# Automaticly generated by [email protected]
1+
# Automaticly generated by [email protected]
2+
cmake_minimum_required(VERSION 3.0)
23

34
add_definitions(-DWSJCPP_VERSION="v0.0.1")
4-
add_definitions(-DWSJCPP_NAME="wsjcpp-arguments")
5+
add_definitions(-DWSJCPP_NAME="wsjcpp/wsjcpp-arguments")
6+
7+
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
8+
set(MACOSX TRUE)
9+
endif()
510

6-
# set(CMAKE_AUTOMOC ON)
711
set(CMAKE_CXX_STANDARD 11)
812

913
set (WSJCPP_LIBRARIES "")
1014
set (WSJCPP_INCLUDE_DIRS "")
1115
set (WSJCPP_SOURCES "")
1216

13-
# wsjcpp/wsjcpp-core
14-
list (APPEND WSJCPP_INCLUDE_DIRS "./src.wsjcpp/wsjcpp_wsjcpp_core")
15-
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_wsjcpp_core/wsjcpp_core.h")
16-
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_wsjcpp_core/wsjcpp_core.cpp")
17+
find_package(Threads REQUIRED)
18+
list (APPEND WSJCPP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
19+
20+
# wsjcpp-core:v0.0.8
21+
list (APPEND WSJCPP_INCLUDE_DIRS "./src.wsjcpp/wsjcpp_core/")
22+
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp")
23+
list (APPEND WSJCPP_SOURCES "./src.wsjcpp/wsjcpp_core/wsjcpp_core.h")
24+
25+
# required-libraries
26+
list (APPEND WSJCPP_LIBRARIES "-lpthread")
27+
28+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
wsjcpp_version: v0.0.1
2+
cmake_cxx_standard: 11
3+
cmake_minimum_required: 3.0
4+
5+
name: wsjcpp-core
6+
version: v0.0.8
7+
description: Basic Utils for wsjcpp
8+
issues: https://github.com/wsjcpp/wsjcpp-core/issues
9+
repositories:
10+
- type: main
11+
url: "https://github.com/wsjcpp/wsjcpp-core"
12+
keywords:
13+
- c++
14+
- wsjcpp
15+
16+
authors:
17+
- name: Evgenii Sopov
18+
19+
20+
distribution:
21+
- source-file: src/wsjcpp_core.cpp
22+
target-file: wsjcpp_core.cpp
23+
type: "source-code"
24+
- source-file: src/wsjcpp_core.h
25+
target-file: wsjcpp_core.h
26+
type: "source-code" # todo must be header-file
27+
- source-file: "src/wsjcpp_unit_tests.cpp"
28+
target-file: "wsjcpp_unit_tests.cpp"
29+
type: "unit-tests"
30+
- source-file: "src/wsjcpp_unit_tests.h"
31+
target-file: "wsjcpp_unit_tests.h"
32+
type: "unit-tests"
33+
- source-file: "src/wsjcpp_unit_tests_main.cpp"
34+
target-file: "wsjcpp_unit_tests_main.cpp"
35+
type: "unit-tests"
36+
37+
unit-tests:
38+
cases:
39+
- name: CoreNormalizePath
40+
description: Check function normalizePath
41+
- name: CoreUuid
42+
description: Check test generate uuid function
43+
- name: CoreExtractFilename
44+
description: Check function extract filenane from path
45+
- name: "ToUpper"
46+
description: "String to upper"
47+
- name: "CreateUuid"
48+
description: "Test generation uuids"
49+
- name: "GetEnv"
50+
description: "Test getEnv function"
51+
- name: "ToLower"
52+
description: "Test toLower"
53+
- name: "ReplaceAll"
54+
description: "Test replace all"
55+
- name: "DecodeUriComponent"
56+
description: "Check decoding"
57+
- name: "EncodeUriComponent"
58+
description: "Check encoding"
59+
- name: "Uint2HexString"
60+
description: "Test convert unsigned int to hex string"
61+
- name: "Split"
62+
description: "Test split function"
63+
- name: "CreateEmptyFile"
64+
description: "Test create empty file"
65+
- name: "ReadFileToBuffer"
66+
description: "test for readFileToBuffer"

0 commit comments

Comments
 (0)