link validation working
This commit is contained in:
parent
47a6e1e522
commit
13aee5d6f5
@ -1,6 +1,5 @@
|
||||
#include "logging.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace logging = boost::log;
|
||||
namespace src = boost::log::sources;
|
||||
@ -27,10 +26,4 @@ void init_logging()
|
||||
);
|
||||
|
||||
logging::add_common_attributes();
|
||||
}
|
||||
|
||||
inline void print_and_log(std::string log_line)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(info) << log_line;
|
||||
std::cout << log_line << std::endl;
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/log/core.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/log/expressions.hpp>
|
||||
@ -8,4 +10,15 @@
|
||||
#include <boost/log/utility/setup/console.hpp>
|
||||
|
||||
void init_logging();
|
||||
void print_and_log(std::string log_line);
|
||||
|
||||
inline void print_and_log(std::string log_line)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(info) << log_line;
|
||||
std::cout << log_line << std::endl;
|
||||
}
|
||||
|
||||
inline void print_and_log_error(std::string log_line)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error) << log_line;
|
||||
std::cout << "ERROR: " << log_line << std::endl;
|
||||
}
|
11
src/main.cpp
11
src/main.cpp
@ -22,7 +22,7 @@ int main(int argc, const char *argv[]) {
|
||||
BOOST_LOG_TRIVIAL(info) << "================================";
|
||||
BOOST_LOG_TRIVIAL(info) << " kc";
|
||||
BOOST_LOG_TRIVIAL(info) << "================================";
|
||||
BOOST_LOG_TRIVIAL(info) << "starting up....";
|
||||
BOOST_LOG_TRIVIAL(info) << "Starting up....";
|
||||
|
||||
auto config = init_config(argc, argv);
|
||||
|
||||
@ -39,15 +39,20 @@ int main(int argc, const char *argv[]) {
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(info) << "command not found";
|
||||
print_and_log_error("Command not found, exiting");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void run_validate(std::shared_ptr<boost::program_options::variables_map> config)
|
||||
{
|
||||
auto env_path = (*config)["path"].as<std::string>();
|
||||
BOOST_LOG_TRIVIAL(info) << "Loading knowledge base from " << env_path;
|
||||
print_and_log("> Loading knowledge base from " + env_path);
|
||||
|
||||
auto file_cache = kc::FileContextCache();
|
||||
file_cache.load(env_path);
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
#include "../logging.hpp"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace kc {
|
||||
@ -11,6 +13,8 @@ std::vector<kc::FileLinkStateResult> validate_links(const std::vector<std::share
|
||||
{
|
||||
std::vector<kc::FileLinkStateResult> ret;
|
||||
|
||||
auto invalid_counter = 0;
|
||||
|
||||
for (auto context : contexts)
|
||||
{
|
||||
if (context->links.size() > 0)
|
||||
@ -25,13 +29,19 @@ std::vector<kc::FileLinkStateResult> validate_links(const std::vector<std::share
|
||||
|
||||
if(!entry.exists())
|
||||
{
|
||||
std::cout << link.link << " + " << context->file_entry->file_entry.path() << " = " << composed << std::endl;
|
||||
print_and_log("Invalid link: " + std::string(context->file_entry->file_entry.path()) + " -> " + link.original_form);
|
||||
invalid_counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (invalid_counter == 0)
|
||||
{
|
||||
print_and_log("All links valid");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user