mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-16 11:35:49 +00:00
Begin work on the new delete action.
This commit is contained in:
parent
e6680b0bf1
commit
8a4afa241e
6 changed files with 179 additions and 1 deletions
|
@ -49,6 +49,7 @@ add_subdirectory(src/scan)
|
|||
add_subdirectory(src/pq)
|
||||
add_subdirectory(src/main)
|
||||
add_subdirectory(src/common)
|
||||
add_subdirectory(src/delete)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
INTERFACE ${PostgreSQL_LIBRARIES}
|
||||
|
|
21
src/delete/CMakeLists.txt
Normal file
21
src/delete/CMakeLists.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
project(${bare_name}-delete CXX C)
|
||||
|
||||
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}"
|
||||
)
|
||||
|
70
src/delete/commandline.cpp
Normal file
70
src/delete/commandline.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
/* Copyright 2015, 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "commandline.hpp"
|
||||
#include "dindexer-common/commandline.hpp"
|
||||
#include <boost/program_options.hpp>
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
namespace din {
|
||||
ValidationError::ValidationError (const po::validation_error& parOther) :
|
||||
po::validation_error(parOther)
|
||||
{
|
||||
}
|
||||
|
||||
const std::string& ValidationError::raw_value() const {
|
||||
auto it_ret = m_substitutions.find("value");
|
||||
return it_ret->second;
|
||||
}
|
||||
|
||||
bool parse_commandline (int parArgc, char* parArgv[], po::variables_map& parVarMap) {
|
||||
po::options_description set_options(ACTION_NAME " options");
|
||||
set_options.add_options()
|
||||
("confirm,c", "Assume yes to all answers")
|
||||
//("option,o", po::value<std::string>()->default_value("default_value"), "Help message")
|
||||
//("option2", po::value<int>(), "Help message")
|
||||
;
|
||||
|
||||
po::options_description positional_options("Positional options");
|
||||
positional_options.add_options()
|
||||
("groupid", po::value<std::vector<uint32_t>>(), "IDs to delete")
|
||||
;
|
||||
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("groupid", -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 ValidationError(err);
|
||||
}
|
||||
|
||||
po::notify(parVarMap);
|
||||
|
||||
if (dinlib::manage_common_commandline(std::cout, ACTION_NAME, "[options...] id [id...]", parVarMap, {std::cref(desc), std::cref(set_options)})) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} //namespace din
|
37
src/delete/commandline.hpp
Normal file
37
src/delete/commandline.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* Copyright 2015, 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef idB6191389C4AD4EE5862CCF1591BE6CE5
|
||||
#define idB6191389C4AD4EE5862CCF1591BE6CE5
|
||||
|
||||
#include <boost/program_options/variables_map.hpp>
|
||||
#include <boost/program_options/errors.hpp>
|
||||
#include "dindexer-common/mediatypes.hpp"
|
||||
|
||||
namespace din {
|
||||
class ValidationError : boost::program_options::validation_error {
|
||||
public:
|
||||
explicit ValidationError ( const boost::program_options::validation_error& parOther );
|
||||
~ValidationError ( void ) noexcept = default;
|
||||
|
||||
const std::string& raw_value ( void ) const;
|
||||
};
|
||||
|
||||
bool parse_commandline ( int parArgc, char* parArgv[], boost::program_options::variables_map& parVarMap );
|
||||
} //namespace din
|
||||
|
||||
#endif
|
49
src/delete/main.cpp
Normal file
49
src/delete/main.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* Copyright 2015, 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "commandline.hpp"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
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;
|
||||
}
|
||||
catch (const din::ValidationError& err) {
|
||||
std::cerr << "Unrecognized id \"" << err.raw_value() << "\", see --help for usage details\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
auto ids = vm["groupid"].as<std::vector<uint32_t>>();
|
||||
std::cout << "Would delete " << ids.size() << " ids: ";
|
||||
for (auto n : ids) {
|
||||
std::cout << n << ", ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ namespace din {
|
|||
type_param_help = oss.str();
|
||||
}
|
||||
|
||||
po::options_description set_options("Set options");
|
||||
po::options_description set_options(ACTION_NAME " options");
|
||||
set_options.add_options()
|
||||
("ignore-errors", "Move on even if reading a file fails. Unreadable files are marked as such in the db.")
|
||||
#if defined(WITH_PROGRESS_FEEDBACK)
|
||||
|
|
Loading…
Add table
Reference in a new issue