项目作者: wsjcpp

项目描述 :
Processors for application arguments
高级语言: C++
项目地址: git://github.com/wsjcpp/wsjcpp-arguments.git
创建时间: 2019-12-10T17:04:43Z
项目社区:https://github.com/wsjcpp/wsjcpp-arguments

开源协议:MIT License

下载


wsjcpp-arguments

Build Status Github Stars Github Stars Github Forks Total alerts Language grade: C/C++

Parsing and handling for application arguments

Intagrate to your project

  1. wsjcpp install "https://github.com/wsjcpp/wsjcpp-arguments:master"

or include this files:

  • src.wsjcpp/wsjcpp_core/wsjcpp_core.h
  • src.wsjcpp/wsjcpp_core/wsjcpp_core.cpp
  • src/wsjcpp_arguments.cpp
  • src/wsjcpp_arguments.h

Example usage

header argument_processor_test_program.h:

  1. #ifndef ARGUMENT_PROCESSOR_MAIN_H
  2. #define ARGUMENT_PROCESSOR_MAIN_H
  3. #include <wsjcpp_arguments.h>
  4. class ArgumentProcessorMain : public WsjcppArgumentProcessor {
  5. public:
  6. ArgumentProcessorMain();
  7. virtual bool applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue);
  8. virtual bool applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName);
  9. virtual int exec(const std::string &sProgramName, const std::vector<std::string> &vSubParams);
  10. };
  11. #endif // ARGUMENT_PROCESSOR_MAIN_H

source-code argument_processor_main.cpp:

  1. #include "argument_processor_main.h"
  2. #include <wsjcpp_core.h>
  3. // ---------------------------------------------------------------------
  4. // ArgumentProcessorMain
  5. ArgumentProcessorMain::ArgumentProcessorMain()
  6. : WsjcppArgumentProcessor("test_program", "TODO description") {
  7. TAG = "ArgumentProcessorMain";
  8. // registrySingleArgument("--single", "What exactly do this single param?");
  9. // registryParameterArgument("-param", "N", "What need this param?");
  10. // registryExample("here example of command");
  11. // registryProcessor(new ArgumentProcessorOtherProcessor());
  12. }
  13. // ---------------------------------------------------------------------
  14. bool ArgumentProcessorMain::applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName) {
  15. WsjcppLog::err(TAG, "Not implemented");
  16. return false;
  17. }
  18. // ---------------------------------------------------------------------
  19. bool ArgumentProcessorMain::applyParameterArgument(
  20. const std::string &sProgramName,
  21. const std::string &sArgumentName,
  22. const std::string &sValue
  23. ) {
  24. WsjcppLog::err(TAG, "Not implemented");
  25. return false;
  26. }
  27. // ---------------------------------------------------------------------
  28. int ArgumentProcessorMain::exec(
  29. const std::vector<std::string> &vRoutes,
  30. const std::vector<std::string> &vSubParams
  31. ) {
  32. WsjcppLog::err(TAG, "Not implemented");
  33. return -1;
  34. }

usage:

  1. #include <wsjcpp_arguments.h>
  2. #include "argument_processor_main.h"
  3. int main(int argc, const char* argv[]) {
  4. ArgumentProcessorMain *pMain = new ArgumentProcessorMain();
  5. WsjcppArguments prog(argc, argv, pMain);
  6. return prog.exec();
  7. }

wsjcpp gen

  1. wsjcpp gen WsjcppArgumentProcessor Main

After this will be created two files by template:

  • src/argument_processor_main.h
  • src/argument_processor_main.cpp