Skip to content

Version 0.2.2 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class " class_name " : public WsjcppArgumentProcessor {
public:
" class_name "();

virtual bool applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue);
virtual bool applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName);
virtual int exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams);
virtual bool applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue) override;
virtual bool applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName) override;
virtual int exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams) override;
};

#endif // " ifndef_header
Expand Down Expand Up @@ -87,7 +87,7 @@ bool " class_name "::applyParameterArgument(

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

Expand Down
2 changes: 1 addition & 1 deletion src.wsjcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Automaticly generated by wsjcpp@v0.1.6
# Automaticly generated by wsjcpp@v0.2.0
cmake_minimum_required(VERSION 3.0)

add_definitions(-DWSJCPP_APP_VERSION="v0.2.1")
Expand Down
7 changes: 7 additions & 0 deletions src.wsjcpp/wsjcpp_core/wsjcpp.hold.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,31 @@ distribution:
- source-file: src/wsjcpp_core.cpp
target-file: wsjcpp_core.cpp
type: "source-code"
sha1: "09ef821bbc090fc1cd8a15bc4a57a9a2ce8ae00d"
- source-file: src/wsjcpp_core.h
target-file: wsjcpp_core.h
type: "source-code" # todo must be header-file
sha1: "e6e4ab2067d3c942db08e3b79862486eaf851e4b"
- source-file: "src/wsjcpp_unit_tests.cpp"
target-file: "wsjcpp_unit_tests.cpp"
type: "unit-tests"
sha1: "fd5989d1a83c8b90bdc4d5e9bc9c3051eaa1e6d2"
- source-file: "src/wsjcpp_unit_tests.h"
target-file: "wsjcpp_unit_tests.h"
type: "unit-tests"
sha1: "83d4b6e046b6b58c42882ccae4be413e03c401c1"
- source-file: "src/wsjcpp_unit_tests_main.cpp"
target-file: "wsjcpp_unit_tests_main.cpp"
type: "unit-tests"
sha1: "388ae269b325c5e161f6c3a5c598575714a4bffc"
- source-file: "scripts.wsjcpp/generate.WsjcppUnitTest.wsjcpp-script"
target-file: "generate.WsjcppUnitTest.wsjcpp-script"
type: "safe-scripting-generate"
sha1: "a7c9c2d19bf81c5b00e659384b0b92a99319a4c1"
- source-file: "scripts.wsjcpp/generate.Class.wsjcpp-script"
target-file: "generate.Class.wsjcpp-script"
type: "safe-scripting-generate"
sha1: "de1799907c685d606b93e08b821b540c2faa2db1"

unit-tests:
cases:
Expand Down
27 changes: 19 additions & 8 deletions src/ArgumentProcessors/argument_processor_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ArgumentProcessorMain::ArgumentProcessorMain()
registryParameterArgument("-param2", "P", "Param 2");
registryExample("wsjcpp --single1 -param1 1");
registryProcessor(new ArgumentProcessorSubcommand1());
registryProcessor(new ArgumentProcessorNothing());
}

// ---------------------------------------------------------------------
Expand All @@ -34,14 +35,6 @@ bool ArgumentProcessorMain::applyParameterArgument(
return false;
}

// ---------------------------------------------------------------------

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


// ---------------------------------------------------------------------
// ArgumentProcessorSubcommand1

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

// ---------------------------------------------------------------------
// ArgumentProcessorNothing

ArgumentProcessorNothing::ArgumentProcessorNothing()
: WsjcppArgumentProcessor(
{"nothing", "n"},
"nothing",
"Example of nothing with long description must be here 12345678901234567890 lol again"
) {
TAG = "ArgumentProcessorSubcommand1";
}

// ---------------------------------------------------------------------

int ArgumentProcessorNothing::exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams) {
std::cout << "Nothing" << std::endl;
return 0;
}
9 changes: 6 additions & 3 deletions src/ArgumentProcessors/argument_processor_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
class ArgumentProcessorMain : public WsjcppArgumentProcessor {
public:
ArgumentProcessorMain();


virtual bool applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName);
virtual bool applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue);
virtual int exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams);
};

class ArgumentProcessorSubcommand1 : public WsjcppArgumentProcessor {
Expand All @@ -26,4 +23,10 @@ class ArgumentProcessorSubcommand1 : public WsjcppArgumentProcessor {
int m_nTimesTest;
};

class ArgumentProcessorNothing : public WsjcppArgumentProcessor {
public:
ArgumentProcessorNothing();
virtual int exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams) override;
};

#endif // ARGUMENT_PROCESSOR_MAIN_H
63 changes: 50 additions & 13 deletions src/wsjcpp_arguments.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "wsjcpp_arguments.h"
#include <wsjcpp_core.h>

// ---------------------------------------------------------------------
// WsjcppArgumentSingle

WsjcppArgumentSingle::WsjcppArgumentSingle(const std::string &sName, const std::string &sDescription) {
TAG = "WsjcppArgumentSingle-" + sName;
m_sName = sName;
Expand All @@ -20,6 +23,7 @@ std::string WsjcppArgumentSingle::getDescription() {
}

// ---------------------------------------------------------------------
// WsjcppArgumentParameter

WsjcppArgumentParameter::WsjcppArgumentParameter(
const std::string &sName,
Expand Down Expand Up @@ -63,6 +67,7 @@ void WsjcppArgumentParameter::setValue(const std::string &sValue) {
}

// ---------------------------------------------------------------------
// WsjcppArgumentProcessor

WsjcppArgumentProcessor::WsjcppArgumentProcessor(
const std::vector<std::string> &vNames,
Expand Down Expand Up @@ -293,20 +298,38 @@ int WsjcppArgumentProcessor::help(

for (int i = 0; i < m_vProcessors.size(); i++) {
WsjcppArgumentProcessor *pProc = m_vProcessors[i];

std::cout
<< " " << pProc->getNamesAsString() << " [<options>...]"
<< std::endl
<< " Subcommand. Try help for more. " << pProc->getDescription()
<< std::endl
<< std::endl;
std::cout << " " << pProc->getNamesAsString();

if (pProc->hasMoreOptions()) {
std::cout
<< " [<options>...]"
<< std::endl
<< " Subcommand. Try help for more. " << pProc->getDescription()
<< std::endl
;
} else {
std::cout
<< std::endl
<< " " << pProc->getDescription()
<< std::endl
;
}
std::cout << std::endl;
}
}
return 0;
}

// ---------------------------------------------------------------------

bool WsjcppArgumentProcessor::hasMoreOptions() {
return m_vProcessors.size() > 0
|| m_vSingleArguments.size() > 0
|| m_vParameterArguments.size() > 0;
}

// ---------------------------------------------------------------------

bool WsjcppArgumentProcessor::applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName) {
WsjcppLog::throw_err(TAG, "No support single argument '" + sArgumentName + "'");
return false;
Expand All @@ -315,18 +338,19 @@ bool WsjcppArgumentProcessor::applySingleArgument(const std::string &sProgramNam
// ---------------------------------------------------------------------

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

// ---------------------------------------------------------------------

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

// ---------------------------------------------------------------------
// WsjcppArguments

WsjcppArguments::WsjcppArguments(int argc, const char* argv[], WsjcppArgumentProcessor *pRoot) {
TAG = "WsjcppArguments";
Expand All @@ -336,12 +360,21 @@ WsjcppArguments::WsjcppArguments(int argc, const char* argv[], WsjcppArgumentPro
m_sProgramName = m_vArguments[0];
m_vArguments.erase(m_vArguments.begin());
m_pRoot = pRoot;
m_bEnablePrintAutoHelp = true;
}

// ---------------------------------------------------------------------

WsjcppArguments::~WsjcppArguments() {
// TODO
for (int i = 0; i < m_vProcessors.size(); i++) {
delete m_vProcessors[i];
}
}

// ---------------------------------------------------------------------

void WsjcppArguments::enablePrintAutoHelp(bool bEnablePrintAutoHelp) {
m_bEnablePrintAutoHelp = bEnablePrintAutoHelp;
}

// ---------------------------------------------------------------------
Expand Down Expand Up @@ -398,8 +431,12 @@ int WsjcppArguments::recursiveExec(
if (vSubArguments.size() > 0 && vSubArguments[0] == "help") {
return pArgumentProcessor->help(vRoutes, vSubArguments);
}

return pArgumentProcessor->exec(vRoutes, vSubArguments);

int nResult = pArgumentProcessor->exec(vRoutes, vSubArguments);
if (nResult == -10 && m_bEnablePrintAutoHelp) {
pArgumentProcessor->help(vRoutes, vSubArguments);
}
return nResult;
}

// ---------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion src/wsjcpp_arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ class WsjcppArgumentProcessor {
WsjcppArgumentParameter *findRegisteredParameterArgument(const std::string &sArgumentName);

bool hasRegisteredArgumentName(const std::string &sArgumentName);

bool getValueOfParam(const std::string &sArgumentName);
int help(
const std::vector<std::string> &vRoutes,
const std::vector<std::string> &vSubParams
);
bool hasMoreOptions();

virtual bool applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName);
virtual bool applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue);
Expand Down Expand Up @@ -112,6 +113,7 @@ class WsjcppArguments {
public:
WsjcppArguments(int argc, const char* argv[], WsjcppArgumentProcessor *pRoot);
~WsjcppArguments();
void enablePrintAutoHelp(bool bEnablePrintAutoHelp);
int exec();

private:
Expand All @@ -131,7 +133,9 @@ class WsjcppArguments {
std::string TAG;
std::vector<std::string> m_vArguments;
std::string m_sProgramName;
bool m_bEnablePrintAutoHelp;
std::vector<WsjcppArgumentProcessor *> m_vProcessors;

};

// ---------------------------------------------------------------------
Expand Down
12 changes: 1 addition & 11 deletions unit-tests.wsjcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Automaticly generated by wsjcpp@v0.1.6
# Automaticly generated by wsjcpp@v0.2.0
cmake_minimum_required(VERSION 3.0)

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

# unit-tests
list (APPEND WSJCPP_INCLUDE_DIRS "src")
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_arguments_with_params.h")
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_arguments_with_params.cpp")
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_simple_arguments.h")
list (APPEND WSJCPP_SOURCES "../unit-tests.wsjcpp/src/unit_test_simple_arguments.cpp")

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

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

install(
TARGETS
"unit-tests"
RUNTIME DESTINATION
/usr/bin
)


2 changes: 1 addition & 1 deletion unit-tests.wsjcpp/build_simple.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

if [ ! -d tmp ]; then
mkdir -p tmp
mkdir -p tmp
fi

cd tmp
Expand Down
11 changes: 10 additions & 1 deletion unit-tests.wsjcpp/src/unit_test_arguments_with_params.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "unit_test_arguments_with_params.h"
#include <wsjcpp_unit_tests.h>
#include <vector>
#include <wsjcpp_core.h>
#include <wsjcpp_arguments.h>
Expand Down Expand Up @@ -52,6 +52,15 @@ class ArgumentProcessorUninstall : public WsjcppArgumentProcessor {
};

// ---------------------------------------------------------------------
// UnitTestArgumentsWithParams

class UnitTestArgumentsWithParams : public WsjcppUnitTestBase {
public:
UnitTestArgumentsWithParams();
virtual bool doBeforeTest() override;
virtual void executeTest() override;
virtual bool doAfterTest() override;
};

REGISTRY_WSJCPP_UNIT_TEST(UnitTestArgumentsWithParams)

Expand Down
16 changes: 0 additions & 16 deletions unit-tests.wsjcpp/src/unit_test_arguments_with_params.h

This file was deleted.

10 changes: 9 additions & 1 deletion unit-tests.wsjcpp/src/unit_test_simple_arguments.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "unit_test_simple_arguments.h"
#include <wsjcpp_unit_tests.h>
#include <vector>
#include <wsjcpp_core.h>
#include <wsjcpp_arguments.h>
Expand Down Expand Up @@ -171,6 +171,14 @@ int ArgumentProcessorProgram1::exec(const std::vector<std::string> &vRoutes, con
// ---------------------------------------------------------------------
// UnitTestSimpleArguments

class UnitTestSimpleArguments : public WsjcppUnitTestBase {
public:
UnitTestSimpleArguments();
virtual bool doBeforeTest() override;
virtual void executeTest() override;
virtual bool doAfterTest() override;
};

REGISTRY_WSJCPP_UNIT_TEST(UnitTestSimpleArguments)

UnitTestSimpleArguments::UnitTestSimpleArguments()
Expand Down
Loading