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
|
||||
run: |
|
||||
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
|
||||
run: |
|
||||
make
|
||||
|
||||
@@ -6,6 +6,9 @@ infoconv: infoconv.cpp
|
||||
infoedit: infoedit.hpp infoedit.cpp
|
||||
$(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 /usr/local/bin/infoconv
|
||||
install infoedit /usr/local/bin/infoedit
|
||||
|
||||
+8
-12
@@ -10,10 +10,10 @@ static void
|
||||
usage()
|
||||
{
|
||||
std::cerr << "USAGE\n"
|
||||
" infoconv info2json < config.info > config.json\n"
|
||||
" infoconv json2info < config.info > config.info\n"
|
||||
" infoconv info2xml < config.info > config.xml\n"
|
||||
" infoconv xml2info < config.xml > config.info\n";
|
||||
" infoconv info2json < config.info > config.json\n"
|
||||
" infoconv json2info < config.info > config.info\n"
|
||||
" infoconv info2xml < config.info > config.xml\n"
|
||||
" infoconv xml2info < config.xml > config.info\n";
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -58,17 +58,13 @@ main(int argc, char** argv)
|
||||
std::string action(argv[1]);
|
||||
if (action == "info2json") {
|
||||
info2json();
|
||||
}
|
||||
else if (action == "json2info") {
|
||||
} else if (action == "json2info") {
|
||||
json2info();
|
||||
}
|
||||
else if (action == "info2xml") {
|
||||
} else if (action == "info2xml") {
|
||||
info2xml();
|
||||
}
|
||||
else if (action == "xml2info") {
|
||||
} else if (action == "xml2info") {
|
||||
xml2info();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
usage();
|
||||
return 2;
|
||||
}
|
||||
|
||||
+26
-35
@@ -14,10 +14,10 @@
|
||||
*/
|
||||
|
||||
#include "infoedit.hpp"
|
||||
#include <iostream>
|
||||
#include <boost/program_options/options_description.hpp>
|
||||
#include <boost/program_options/variables_map.hpp>
|
||||
#include <boost/program_options/parsers.hpp>
|
||||
#include <boost/program_options/variables_map.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace infoedit {
|
||||
|
||||
@@ -31,8 +31,7 @@ InfoEditor::load(const std::string& fileName)
|
||||
|
||||
try {
|
||||
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;
|
||||
msg << "Failed to parse configuration file";
|
||||
msg << " " << error.message() << " line " << error.line();
|
||||
@@ -62,8 +61,7 @@ InfoEditor::remove(const std::string& section)
|
||||
std::size_t pos = section.find_last_of(".");
|
||||
if (pos == std::string::npos) {
|
||||
m_info.erase(section.c_str());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
boost::optional<boost::property_tree::ptree&> child =
|
||||
m_info.get_child_optional(section.substr(0, pos));
|
||||
if (child) {
|
||||
@@ -101,50 +99,45 @@ main(int argc, char** argv)
|
||||
std::string value;
|
||||
|
||||
namespace po = boost::program_options;
|
||||
po::options_description description("Usage\n"
|
||||
" infoedit [-f file] [-s|d|a|r path] [-v value]\n"
|
||||
"Options");
|
||||
|
||||
description.add_options()
|
||||
("help,h", "print this help message")
|
||||
("file,f", po::value<std::string>(&configFile), "the file to edit")
|
||||
("section,s", po::value<std::string>(§ionPath), "the section to modify")
|
||||
("path,p", po::value<std::string>(§ionPath), "the path to add - can be duplicate")
|
||||
("value,v", po::value<std::string>(&value), "the value used to modify some section or add path")
|
||||
("delete,d", po::value<std::string>(§ionPath), "the sub tree to delete")
|
||||
("add,a", po::value<std::string>(§ionPath), "adds a sub tree")
|
||||
("replace,r", po::value<std::string>(§ionPath), "replace the sub tree")
|
||||
;
|
||||
po::options_description opts("Usage\n"
|
||||
" infoedit [-f file] [-s|d|a|r path] [-v value]\n"
|
||||
"Options");
|
||||
opts.add_options()("help,h", "print this help message");
|
||||
opts.add_options()("file,f", po::value<std::string>(&configFile), "the file to edit");
|
||||
opts.add_options()("section,s", po::value<std::string>(§ionPath), "the section to modify");
|
||||
opts.add_options()("path,p", po::value<std::string>(§ionPath),
|
||||
"the path to add - can be duplicate");
|
||||
opts.add_options()("value,v", po::value<std::string>(&value),
|
||||
"the value used to modify some section or add path");
|
||||
opts.add_options()("delete,d", po::value<std::string>(§ionPath), "the sub tree to delete");
|
||||
opts.add_options()("add,a", po::value<std::string>(§ionPath), "adds a sub tree");
|
||||
opts.add_options()("replace,r", po::value<std::string>(§ionPath), "replace the sub tree");
|
||||
|
||||
po::variables_map vm;
|
||||
try {
|
||||
po::store(po::command_line_parser(argc, argv).options(description).run(), vm);
|
||||
po::notify(vm);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "ERROR: " << e.what()
|
||||
<< "\n"
|
||||
<< description;
|
||||
po::store(po::command_line_parser(argc, argv).options(opts).run(), vm);
|
||||
po::notify(vm);
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "ERROR: " << e.what() << "\n" << opts;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (vm.count("help") > 0) {
|
||||
std::cout << description;
|
||||
std::cout << opts;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vm.count("file") == 0) {
|
||||
std::cerr << "ERROR: the file to edit should be specified"
|
||||
<< "\n"
|
||||
<< description;
|
||||
<< opts;
|
||||
return 1;
|
||||
}
|
||||
|
||||
InfoEditor editor;
|
||||
try {
|
||||
editor.load(configFile);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
@@ -179,15 +172,13 @@ main(int argc, char** argv)
|
||||
if (vm.count("replace") > 0) {
|
||||
editor.remove(sectionPath).insert(sectionPath, std::cin);
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
editor.save(configFile);
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cerr << "Unable to save the edit to file" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
+9
-16
@@ -16,10 +16,10 @@
|
||||
#ifndef 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 <iostream>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/info_parser.hpp>
|
||||
|
||||
namespace infoedit {
|
||||
|
||||
@@ -31,28 +31,21 @@ public:
|
||||
public:
|
||||
Error(const std::string& what)
|
||||
: std::runtime_error(what)
|
||||
{
|
||||
}
|
||||
{}
|
||||
};
|
||||
|
||||
public:
|
||||
void
|
||||
load(const std::string& fileName);
|
||||
void load(const std::string& fileName);
|
||||
|
||||
InfoEditor&
|
||||
modify(const std::string& section, const std::string& value);
|
||||
InfoEditor& modify(const std::string& section, const std::string& value);
|
||||
|
||||
InfoEditor&
|
||||
add(const std::string& section, const std::string& value);
|
||||
InfoEditor& add(const std::string& section, const std::string& value);
|
||||
|
||||
InfoEditor&
|
||||
remove(const std::string& section);
|
||||
InfoEditor& remove(const std::string& section);
|
||||
|
||||
InfoEditor&
|
||||
insert(const std::string& section, std::istream& stream);
|
||||
InfoEditor& insert(const std::string& section, std::istream& stream);
|
||||
|
||||
void
|
||||
save(const std::string& fileName);
|
||||
void save(const std::string& fileName);
|
||||
|
||||
private:
|
||||
boost::property_tree::ptree m_info;
|
||||
|
||||
Reference in new issue
Block a user