mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-07-03 14:14:11 +00:00
Accept a comma-separated list of tags as the first parameter in tag
This commit is contained in:
parent
51173100bf
commit
6afc16fe5b
5 changed files with 96 additions and 3 deletions
|
@ -3,6 +3,7 @@ project(${bare_name}-tag CXX)
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
main.cpp
|
main.cpp
|
||||||
commandline.cpp
|
commandline.cpp
|
||||||
|
split_tags.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME}
|
target_include_directories(${PROJECT_NAME}
|
||||||
|
|
|
@ -34,6 +34,7 @@ namespace din {
|
||||||
|
|
||||||
po::options_description positional_options("Positional options");
|
po::options_description positional_options("Positional options");
|
||||||
positional_options.add_options()
|
positional_options.add_options()
|
||||||
|
("tags", po::value<std::string>(), "comma-separated tag list")
|
||||||
("ids", po::value<std::vector<uint64_t>>(), "pos_option description")
|
("ids", po::value<std::vector<uint64_t>>(), "pos_option description")
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ namespace din {
|
||||||
po::options_description all("Available options");
|
po::options_description all("Available options");
|
||||||
po::positional_options_description pd;
|
po::positional_options_description pd;
|
||||||
all.add(desc).add(positional_options).add(set_options);
|
all.add(desc).add(positional_options).add(set_options);
|
||||||
pd.add("ids", -1);//.add("pos_option2", 1);
|
pd.add("tags", 1).add("ids", -1);
|
||||||
try {
|
try {
|
||||||
po::store(po::command_line_parser(parArgc, parArgv).options(all).positional(pd).run(), parVarMap);
|
po::store(po::command_line_parser(parArgc, parArgv).options(all).positional(pd).run(), parVarMap);
|
||||||
}
|
}
|
||||||
|
@ -51,7 +52,8 @@ namespace din {
|
||||||
|
|
||||||
po::notify(parVarMap);
|
po::notify(parVarMap);
|
||||||
|
|
||||||
if (dinlib::manage_common_commandline(std::cout, ACTION_NAME, "[options...] ids...", parVarMap, {std::cref(desc), std::cref(set_options)})) {
|
const char* const help_text = "[options...] tag[,tag2...] ids...";
|
||||||
|
if (dinlib::manage_common_commandline(std::cout, ACTION_NAME, help_text, parVarMap, {std::cref(desc), std::cref(set_options)})) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "commandline.hpp"
|
#include "commandline.hpp"
|
||||||
#include "tag_postgres.hpp"
|
#include "split_tags.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
} //unnamed namespace
|
||||||
|
|
||||||
int main (int parArgc, char* parArgv[]) {
|
int main (int parArgc, char* parArgv[]) {
|
||||||
using boost::program_options::variables_map;
|
using boost::program_options::variables_map;
|
||||||
|
|
||||||
|
@ -43,5 +46,12 @@ int main (int parArgc, char* parArgv[]) {
|
||||||
for (auto id : ids) {
|
for (auto id : ids) {
|
||||||
std::cout << id << '\n';
|
std::cout << id << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto master_tags_string = vm["tags"].as<std::string>();
|
||||||
|
std::vector<boost::string_ref> tags = din::split_tags(master_tags_string);
|
||||||
|
|
||||||
|
for (auto tag : tags) {
|
||||||
|
std::cout << '"' << tag << "\"\n";
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
50
src/tag/split_tags.cpp
Normal file
50
src/tag/split_tags.cpp
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "split_tags.hpp"
|
||||||
|
#include <boost/algorithm/string/finder.hpp>
|
||||||
|
#include <boost/algorithm/string/split.hpp>
|
||||||
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
|
#include <boost/utility/string_ref.hpp>
|
||||||
|
#include <boost/range/adaptor/transformed.hpp>
|
||||||
|
#include <boost/range/adaptor/filtered.hpp>
|
||||||
|
|
||||||
|
namespace din {
|
||||||
|
std::vector<boost::string_ref> split_tags (const std::string& parCommaSeparatedList) {
|
||||||
|
using OutRange = boost::iterator_range<std::string::const_iterator>;
|
||||||
|
using boost::token_finder;
|
||||||
|
using boost::adaptors::transformed;
|
||||||
|
using boost::adaptors::filtered;
|
||||||
|
using boost::string_ref;
|
||||||
|
using boost::iter_split;
|
||||||
|
using boost::trim_copy;
|
||||||
|
|
||||||
|
std::vector<OutRange> out_range;
|
||||||
|
|
||||||
|
//See:
|
||||||
|
//https://stackoverflow.com/questions/27999941/how-to-use-boostsplit-with-booststring-ref-in-boost-1-55
|
||||||
|
//http://www.boost.org/doc/libs/1_60_0/doc/html/boost/algorithm/iter_split.html
|
||||||
|
//http://www.boost.org/doc/libs/1_60_0/doc/html/boost/algorithm/token_finder.html
|
||||||
|
//https://stackoverflow.com/questions/20781090/difference-between-boostsplit-vs-boostiter-split
|
||||||
|
return boost::copy_range<std::vector<string_ref>>(
|
||||||
|
iter_split(out_range, parCommaSeparatedList, token_finder([](char c){return ','==c;})) |
|
||||||
|
transformed([](const OutRange& r){return trim_copy(r);}) |
|
||||||
|
transformed([](const OutRange& r){return string_ref(&*r.begin(), r.size());}) |
|
||||||
|
filtered([](const string_ref& r){return not r.empty();})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} //namespace din
|
30
src/tag/split_tags.hpp
Normal file
30
src/tag/split_tags.hpp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef id913CE9D2F60745349F39F2C82455973E
|
||||||
|
#define id913CE9D2F60745349F39F2C82455973E
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <boost/utility/string_ref.hpp>
|
||||||
|
#include "helpers/compatibility.h"
|
||||||
|
|
||||||
|
namespace din {
|
||||||
|
std::vector<boost::string_ref> split_tags ( const std::string& parCommaSeparatedList ) a_pure;
|
||||||
|
} //namespace din
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue