ci: enforce code style
This commit is contained in:
1 parent
fe53f9ba54
commit
61fcdd9aa0
6 files changed
+58
-63
No files matched your search
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
BasedOnStyle: Mozilla
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
ColumnLimit: 100
|
||||||
|
ReflowComments: true
|
||||||
|
SortIncludes: true
|
||||||
@@ -9,6 +9,10 @@ jobs:
|
|||||||
- name: install dependencies
|
- name: install dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get install libboost-dev libboost-program-options-dev
|
sudo apt-get install libboost-dev libboost-program-options-dev
|
||||||
|
- name: check code style
|
||||||
|
run: |
|
||||||
|
make lint
|
||||||
|
[[ $(git status --porcelain | tee >(cat 1>&2) | wc -l) -eq 0 ]]
|
||||||
- name: build and install
|
- name: build and install
|
||||||
run: |
|
run: |
|
||||||
make
|
make
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ infoconv: infoconv.cpp
|
|||||||
infoedit: infoedit.hpp infoedit.cpp
|
infoedit: infoedit.hpp infoedit.cpp
|
||||||
$(CXX) -o infoedit -std=c++11 infoedit.cpp -lboost_program_options
|
$(CXX) -o infoedit -std=c++11 infoedit.cpp -lboost_program_options
|
||||||
|
|
||||||
|
lint:
|
||||||
|
clang-format-8 -i -style=file *.[hc]pp
|
||||||
|
|
||||||
install: infoconv infoedit
|
install: infoconv infoedit
|
||||||
install infoconv /usr/local/bin/infoconv
|
install infoconv /usr/local/bin/infoconv
|
||||||
install infoedit /usr/local/bin/infoedit
|
install infoedit /usr/local/bin/infoedit
|
||||||
|
|||||||
+8
-12
@@ -10,10 +10,10 @@ static void
|
|||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
std::cerr << "USAGE\n"
|
std::cerr << "USAGE\n"
|
||||||
" infoconv info2json < config.info > config.json\n"
|
" infoconv info2json < config.info > config.json\n"
|
||||||
" infoconv json2info < config.info > config.info\n"
|
" infoconv json2info < config.info > config.info\n"
|
||||||
" infoconv info2xml < config.info > config.xml\n"
|
" infoconv info2xml < config.info > config.xml\n"
|
||||||
" infoconv xml2info < config.xml > config.info\n";
|
" infoconv xml2info < config.xml > config.info\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -58,17 +58,13 @@ main(int argc, char** argv)
|
|||||||
std::string action(argv[1]);
|
std::string action(argv[1]);
|
||||||
if (action == "info2json") {
|
if (action == "info2json") {
|
||||||
info2json();
|
info2json();
|
||||||
}
|
} else if (action == "json2info") {
|
||||||
else if (action == "json2info") {
|
|
||||||
json2info();
|
json2info();
|
||||||
}
|
} else if (action == "info2xml") {
|
||||||
else if (action == "info2xml") {
|
|
||||||
info2xml();
|
info2xml();
|
||||||
}
|
} else if (action == "xml2info") {
|
||||||
else if (action == "xml2info") {
|
|
||||||
xml2info();
|
xml2info();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
usage();
|
usage();
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-35
@@ -14,10 +14,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "infoedit.hpp"
|
#include "infoedit.hpp"
|
||||||
#include <iostream>
|
|
||||||
#include <boost/program_options/options_description.hpp>
|
#include <boost/program_options/options_description.hpp>
|
||||||
#include <boost/program_options/variables_map.hpp>
|
|
||||||
#include <boost/program_options/parsers.hpp>
|
#include <boost/program_options/parsers.hpp>
|
||||||
|
#include <boost/program_options/variables_map.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace infoedit {
|
namespace infoedit {
|
||||||
|
|
||||||
@@ -31,8 +31,7 @@ InfoEditor::load(const std::string& fileName)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
boost::property_tree::info_parser::read_info(input, m_info);
|
boost::property_tree::info_parser::read_info(input, m_info);
|
||||||
}
|
} catch (boost::property_tree::info_parser::info_parser_error& error) {
|
||||||
catch (boost::property_tree::info_parser::info_parser_error& error) {
|
|
||||||
std::stringstream msg;
|
std::stringstream msg;
|
||||||
msg << "Failed to parse configuration file";
|
msg << "Failed to parse configuration file";
|
||||||
msg << " " << error.message() << " line " << error.line();
|
msg << " " << error.message() << " line " << error.line();
|
||||||
@@ -62,8 +61,7 @@ InfoEditor::remove(const std::string& section)
|
|||||||
std::size_t pos = section.find_last_of(".");
|
std::size_t pos = section.find_last_of(".");
|
||||||
if (pos == std::string::npos) {
|
if (pos == std::string::npos) {
|
||||||
m_info.erase(section.c_str());
|
m_info.erase(section.c_str());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
boost::optional<boost::property_tree::ptree&> child =
|
boost::optional<boost::property_tree::ptree&> child =
|
||||||
m_info.get_child_optional(section.substr(0, pos));
|
m_info.get_child_optional(section.substr(0, pos));
|
||||||
if (child) {
|
if (child) {
|
||||||
@@ -101,50 +99,45 @@ main(int argc, char** argv)
|
|||||||
std::string value;
|
std::string value;
|
||||||
|
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
po::options_description description("Usage\n"
|
po::options_description opts("Usage\n"
|
||||||
" infoedit [-f file] [-s|d|a|r path] [-v value]\n"
|
" infoedit [-f file] [-s|d|a|r path] [-v value]\n"
|
||||||
"Options");
|
"Options");
|
||||||
|
opts.add_options()("help,h", "print this help message");
|
||||||
description.add_options()
|
opts.add_options()("file,f", po::value<std::string>(&configFile), "the file to edit");
|
||||||
("help,h", "print this help message")
|
opts.add_options()("section,s", po::value<std::string>(§ionPath), "the section to modify");
|
||||||
("file,f", po::value<std::string>(&configFile), "the file to edit")
|
opts.add_options()("path,p", po::value<std::string>(§ionPath),
|
||||||
("section,s", po::value<std::string>(§ionPath), "the section to modify")
|
"the path to add - can be duplicate");
|
||||||
("path,p", po::value<std::string>(§ionPath), "the path to add - can be duplicate")
|
opts.add_options()("value,v", po::value<std::string>(&value),
|
||||||
("value,v", po::value<std::string>(&value), "the value used to modify some section or add path")
|
"the value used to modify some section or add path");
|
||||||
("delete,d", po::value<std::string>(§ionPath), "the sub tree to delete")
|
opts.add_options()("delete,d", po::value<std::string>(§ionPath), "the sub tree to delete");
|
||||||
("add,a", po::value<std::string>(§ionPath), "adds a sub tree")
|
opts.add_options()("add,a", po::value<std::string>(§ionPath), "adds a sub tree");
|
||||||
("replace,r", po::value<std::string>(§ionPath), "replace the sub tree")
|
opts.add_options()("replace,r", po::value<std::string>(§ionPath), "replace the sub tree");
|
||||||
;
|
|
||||||
|
|
||||||
po::variables_map vm;
|
po::variables_map vm;
|
||||||
try {
|
try {
|
||||||
po::store(po::command_line_parser(argc, argv).options(description).run(), vm);
|
po::store(po::command_line_parser(argc, argv).options(opts).run(), vm);
|
||||||
po::notify(vm);
|
po::notify(vm);
|
||||||
}
|
} catch (const std::exception& e) {
|
||||||
catch (const std::exception& e) {
|
std::cerr << "ERROR: " << e.what() << "\n" << opts;
|
||||||
std::cerr << "ERROR: " << e.what()
|
|
||||||
<< "\n"
|
|
||||||
<< description;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm.count("help") > 0) {
|
if (vm.count("help") > 0) {
|
||||||
std::cout << description;
|
std::cout << opts;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm.count("file") == 0) {
|
if (vm.count("file") == 0) {
|
||||||
std::cerr << "ERROR: the file to edit should be specified"
|
std::cerr << "ERROR: the file to edit should be specified"
|
||||||
<< "\n"
|
<< "\n"
|
||||||
<< description;
|
<< opts;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
InfoEditor editor;
|
InfoEditor editor;
|
||||||
try {
|
try {
|
||||||
editor.load(configFile);
|
editor.load(configFile);
|
||||||
}
|
} catch (const std::exception& e) {
|
||||||
catch (const std::exception& e) {
|
|
||||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -179,15 +172,13 @@ main(int argc, char** argv)
|
|||||||
if (vm.count("replace") > 0) {
|
if (vm.count("replace") > 0) {
|
||||||
editor.remove(sectionPath).insert(sectionPath, std::cin);
|
editor.remove(sectionPath).insert(sectionPath, std::cin);
|
||||||
}
|
}
|
||||||
}
|
} catch (...) {
|
||||||
catch (...) {
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
editor.save(configFile);
|
editor.save(configFile);
|
||||||
}
|
} catch (...) {
|
||||||
catch (...) {
|
|
||||||
std::cerr << "Unable to save the edit to file" << std::endl;
|
std::cerr << "Unable to save the edit to file" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-16
@@ -16,10 +16,10 @@
|
|||||||
#ifndef INTEGRATION_TESTS_INSTALL_HELPERS_INFOEDIT_INFOEDIT_HPP
|
#ifndef INTEGRATION_TESTS_INSTALL_HELPERS_INFOEDIT_INFOEDIT_HPP
|
||||||
#define INTEGRATION_TESTS_INSTALL_HELPERS_INFOEDIT_INFOEDIT_HPP
|
#define INTEGRATION_TESTS_INSTALL_HELPERS_INFOEDIT_INFOEDIT_HPP
|
||||||
|
|
||||||
|
#include <boost/property_tree/info_parser.hpp>
|
||||||
|
#include <boost/property_tree/ptree.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <boost/property_tree/ptree.hpp>
|
|
||||||
#include <boost/property_tree/info_parser.hpp>
|
|
||||||
|
|
||||||
namespace infoedit {
|
namespace infoedit {
|
||||||
|
|
||||||
@@ -31,28 +31,21 @@ public:
|
|||||||
public:
|
public:
|
||||||
Error(const std::string& what)
|
Error(const std::string& what)
|
||||||
: std::runtime_error(what)
|
: std::runtime_error(what)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void
|
void load(const std::string& fileName);
|
||||||
load(const std::string& fileName);
|
|
||||||
|
|
||||||
InfoEditor&
|
InfoEditor& modify(const std::string& section, const std::string& value);
|
||||||
modify(const std::string& section, const std::string& value);
|
|
||||||
|
|
||||||
InfoEditor&
|
InfoEditor& add(const std::string& section, const std::string& value);
|
||||||
add(const std::string& section, const std::string& value);
|
|
||||||
|
|
||||||
InfoEditor&
|
InfoEditor& remove(const std::string& section);
|
||||||
remove(const std::string& section);
|
|
||||||
|
|
||||||
InfoEditor&
|
InfoEditor& insert(const std::string& section, std::istream& stream);
|
||||||
insert(const std::string& section, std::istream& stream);
|
|
||||||
|
|
||||||
void
|
void save(const std::string& fileName);
|
||||||
save(const std::string& fileName);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::property_tree::ptree m_info;
|
boost::property_tree::ptree m_info;
|
||||||
|
|||||||
Reference in new issue
Block a user