From a508a22af8fbc389b2828d57d15b91b9c9fc021b Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 4 May 2016 09:43:54 +0200 Subject: [PATCH] New empty action "tag" --- CMakeLists.txt | 1 + src/tag/CMakeLists.txt | 26 ++++++++++++++++++ src/tag/commandline.cpp | 59 +++++++++++++++++++++++++++++++++++++++++ src/tag/commandline.hpp | 28 +++++++++++++++++++ src/tag/main.cpp | 36 +++++++++++++++++++++++++ 5 files changed, 150 insertions(+) create mode 100644 src/tag/CMakeLists.txt create mode 100644 src/tag/commandline.cpp create mode 100644 src/tag/commandline.hpp create mode 100644 src/tag/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 24620b0..645922c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,6 +126,7 @@ add_subdirectory(src/delete) add_subdirectory(src/query) add_subdirectory(src/locate) add_subdirectory(src/navigate) +add_subdirectory(src/tag) #Tests if (BUILD_TESTING) diff --git a/src/tag/CMakeLists.txt b/src/tag/CMakeLists.txt new file mode 100644 index 0000000..9107d4e --- /dev/null +++ b/src/tag/CMakeLists.txt @@ -0,0 +1,26 @@ +project(${bare_name}-tag CXX) + +add_executable(${PROJECT_NAME} + main.cpp + commandline.cpp +) + +target_include_directories(${PROJECT_NAME} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/.. +) + +target_link_libraries(${PROJECT_NAME} + PRIVATE ${bare_name}-if + PRIVATE ${bare_name}-common +) + +string(REPLACE "${bare_name}-" "" ACTION_NAME "${PROJECT_NAME}") +target_compile_definitions(${PROJECT_NAME} + PRIVATE ACTION_NAME="${ACTION_NAME}" +) + +install(TARGETS ${PROJECT_NAME} + LIBRARY DESTINATION lib + RUNTIME DESTINATION ${ACTIONS_PATH_INSTALL} + ARCHIVE DESTINATION lib/static +) diff --git a/src/tag/commandline.cpp b/src/tag/commandline.cpp new file mode 100644 index 0000000..d981a1d --- /dev/null +++ b/src/tag/commandline.cpp @@ -0,0 +1,59 @@ +/* Copyright 2015, 2016, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#include "commandline.hpp" +#include "dindexer-common/commandline.hpp" +#include +#include + +namespace po = boost::program_options; + +namespace din { + bool parse_commandline (int parArgc, char* parArgv[], po::variables_map& parVarMap) { + po::options_description set_options(ACTION_NAME " options"); + //set_options.add_options() + //("switch,s", "Help message") + //("option,o", po::value()->default_value("default_value"), "Help message") + //("option2", po::value(), "Help message") + //; + + //po::options_description positional_options("Positional options"); + //positional_options.add_options() + //("pos_option", po::value(), "pos_option description") + //; + + const auto desc = dinlib::get_default_commandline(); + po::options_description all("Available options"); + //po::positional_options_description pd; + all.add(desc)./*add(positional_options).*/add(set_options); + //pd.add("pos_option", 1);//.add("pos_option2", 1); + try { + po::store(po::command_line_parser(parArgc, parArgv).options(all)/*.positional(pd)*/.run(), parVarMap); + } + catch (const po::validation_error& err) { + throw dinlib::ValidationError(err); + } + + po::notify(parVarMap); + + if (dinlib::manage_common_commandline(std::cout, ACTION_NAME, "[options...] ", parVarMap, {std::cref(desc), std::cref(set_options)})) { + return true; + } + + return false; + } +} //namespace din diff --git a/src/tag/commandline.hpp b/src/tag/commandline.hpp new file mode 100644 index 0000000..55fcada --- /dev/null +++ b/src/tag/commandline.hpp @@ -0,0 +1,28 @@ +/* Copyright 2015, 2016, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#ifndef id1B7A42F6E46547A6AB0F914E2A91399F +#define id1B7A42F6E46547A6AB0F914E2A91399F + +#include "dindexer-common/validationerror.hpp" +#include + +namespace din { + bool parse_commandline ( int parArgc, char* parArgv[], boost::program_options::variables_map& parVarMap ); +} //namespace din + +#endif diff --git a/src/tag/main.cpp b/src/tag/main.cpp new file mode 100644 index 0000000..2e365ae --- /dev/null +++ b/src/tag/main.cpp @@ -0,0 +1,36 @@ +/* Copyright 2015, 2016, Michele Santullo + * This file is part of "dindexer". + * + * "dindexer" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * "dindexer" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with "dindexer". If not, see . + */ + +#include "commandline.hpp" +#include +#include + +int main (int parArgc, char* parArgv[]) { + using boost::program_options::variables_map; + + variables_map vm; + try { + if (din::parse_commandline(parArgc, parArgv, vm)) { + return 0; + } + } + catch (const std::invalid_argument& err) { + std::cerr << err.what() << "\nUse --help for help" << std::endl; + return 2; + } + return 0; +}