ide suggestions
This commit is contained in:
parent
313688622a
commit
1bee729664
@ -5,9 +5,7 @@
|
||||
|
||||
namespace kc {
|
||||
|
||||
AppContext::AppContext()
|
||||
{
|
||||
|
||||
AppContext::AppContext(): config_loaded(false) {
|
||||
}
|
||||
|
||||
void AppContext::load_config(int argc, const char *argv[])
|
||||
@ -18,16 +16,15 @@ void AppContext::load_config(int argc, const char *argv[])
|
||||
|
||||
void AppContext::load_and_parse_cache()
|
||||
{
|
||||
auto env_path = (*config)["path"].as<std::string>();
|
||||
print_and_log("> Loading knowledge base from " + env_path);
|
||||
const auto env_path = (*config)["path"].as<std::string>();
|
||||
print_and_log("Loading knowledge base from " + env_path);
|
||||
|
||||
file_cache = std::make_shared<kc::FileContextCache>();
|
||||
file_cache->load(env_path);
|
||||
file_cache->parse_all();
|
||||
}
|
||||
|
||||
std::string AppContext::command()
|
||||
{
|
||||
std::string AppContext::command() const {
|
||||
if (config->count("command") == 1)
|
||||
{
|
||||
return (*config)["command"].as<std::string>();
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
void load_config(int argc, const char *argv[]);
|
||||
void load_and_parse_cache();
|
||||
|
||||
std::string command();
|
||||
[[nodiscard]] std::string command() const;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -41,20 +41,19 @@ std::shared_ptr<po::variables_map> init_config(int argc, const char *argv[])
|
||||
.run(),
|
||||
*vm);
|
||||
|
||||
if (vm->count("config"))
|
||||
if (vm->contains("config"))
|
||||
{
|
||||
auto config_path = (*vm)["config"].as<std::string>();
|
||||
BOOST_LOG_TRIVIAL(info) << "Attempting file config load for " << config_path;
|
||||
|
||||
std::ifstream ifs{config_path.c_str()};
|
||||
if (ifs) {
|
||||
if (std::ifstream ifs{config_path.c_str()}) {
|
||||
BOOST_LOG_TRIVIAL(info) << "File opened, loading...";
|
||||
po::store(po::parse_config_file(ifs, config_file_options), *vm);
|
||||
}
|
||||
}
|
||||
po::notify(*vm);
|
||||
|
||||
if (vm->count("help")) {
|
||||
if (vm->contains("help")) {
|
||||
std::cout << desc;
|
||||
|
||||
return nullptr;
|
||||
|
@ -2,13 +2,12 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
|
||||
namespace kc {
|
||||
|
||||
FileEntry::FileEntry(fs::directory_entry entry)
|
||||
: file_entry(entry)
|
||||
{
|
||||
|
||||
: file_entry(std::move(entry)), loaded(false) {
|
||||
}
|
||||
|
||||
bool FileEntry::content_loaded() const
|
||||
|
@ -12,14 +12,14 @@ namespace kc {
|
||||
class FileEntry {
|
||||
public:
|
||||
|
||||
FileEntry(fs::directory_entry entry);
|
||||
explicit FileEntry(fs::directory_entry entry);
|
||||
|
||||
fs::directory_entry file_entry;
|
||||
fs::path relative_path;
|
||||
|
||||
bool content_loaded() const;
|
||||
[[nodiscard]] bool content_loaded() const;
|
||||
std::string load_content();
|
||||
std::string get_content() const;
|
||||
[[nodiscard]] std::string get_content() const;
|
||||
void clear_content();
|
||||
|
||||
private:
|
||||
|
@ -8,14 +8,14 @@ static const std::string exclusions[] = {".git", ".obsidian"};
|
||||
std::vector<std::shared_ptr<kc::FileEntry>> kc::walk_dir(const std::string dir)
|
||||
{
|
||||
auto matched = std::vector<std::shared_ptr<kc::FileEntry>>();
|
||||
auto base_path = fs::path(dir);
|
||||
const auto base_path = fs::path(dir);
|
||||
|
||||
for (auto const& dir_entry : fs::recursive_directory_iterator(base_path))
|
||||
{
|
||||
if (dir_entry.is_directory()) continue;
|
||||
|
||||
auto excluded = false;
|
||||
auto dir_entry_path = dir_entry.path();
|
||||
const auto& dir_entry_path = dir_entry.path();
|
||||
auto dir_entry_path_string = dir_entry_path.string();
|
||||
|
||||
for (auto const& exclusion: exclusions)
|
||||
|
10
src/main.cpp
10
src/main.cpp
@ -14,8 +14,8 @@
|
||||
#include "valid/link.hpp"
|
||||
#include "image/img.hpp"
|
||||
|
||||
void run_validate(kc::AppContext app_context);
|
||||
void run_img(kc::AppContext app_context);
|
||||
void run_validate(const kc::AppContext &app_context);
|
||||
void run_img(const kc::AppContext &app_context);
|
||||
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
@ -32,7 +32,7 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
if(app_context.config)
|
||||
{
|
||||
auto command = app_context.command();
|
||||
const auto command = app_context.command();
|
||||
if (!command.empty())
|
||||
{
|
||||
if (command == "validate")
|
||||
@ -58,12 +58,12 @@ int main(int argc, const char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void run_validate(kc::AppContext app_context)
|
||||
void run_validate(const kc::AppContext &app_context)
|
||||
{
|
||||
kc::validate_links(app_context.file_cache->get());
|
||||
}
|
||||
|
||||
void run_img(kc::AppContext app_context)
|
||||
void run_img(const kc::AppContext &app_context)
|
||||
{
|
||||
kc::image_proc(app_context.file_cache->get());
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
#include "FileContext.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace kc {
|
||||
|
||||
FileContext::FileContext(std::shared_ptr<kc::FileEntry> entry)
|
||||
: file_entry(entry)
|
||||
{
|
||||
|
||||
: file_entry(std::move(entry)), links_parsed(false) {
|
||||
}
|
||||
|
||||
void FileContext::parse()
|
||||
|
@ -14,7 +14,7 @@ namespace kc {
|
||||
class FileContext {
|
||||
public:
|
||||
|
||||
FileContext(std::shared_ptr<kc::FileEntry> entry);
|
||||
explicit FileContext(std::shared_ptr<kc::FileEntry> entry);
|
||||
|
||||
std::shared_ptr<kc::FileEntry> file_entry;
|
||||
std::vector<kc::Link> links;
|
||||
|
@ -8,14 +8,14 @@
|
||||
|
||||
namespace kc {
|
||||
|
||||
void FileContextCache::load(const std::string root_path)
|
||||
void FileContextCache::load(const std::string &root_path)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(trace) << "Beginning cache load";
|
||||
|
||||
auto entries = kc::walk_dir(root_path);
|
||||
const auto entries = kc::walk_dir(root_path);
|
||||
this->root_path.assign(root_path);
|
||||
|
||||
for (auto entry : entries)
|
||||
for (const auto& entry : entries)
|
||||
{
|
||||
if (entry->relative_path.extension() == ".md")
|
||||
{
|
||||
@ -43,9 +43,9 @@ void FileContextCache::parse_all()
|
||||
{
|
||||
context->parse();
|
||||
|
||||
if (context->tags.size() != 0)
|
||||
if (!context->tags.empty())
|
||||
{
|
||||
for (auto tag : context->tags)
|
||||
for (const auto& tag : context->tags)
|
||||
{
|
||||
tag_map[tag].push_back(context->file_entry);
|
||||
}
|
||||
|
@ -10,12 +10,12 @@ namespace kc {
|
||||
|
||||
class FileContextCache {
|
||||
public:
|
||||
void load(std::string root_path);
|
||||
void load(const std::string &root_path);
|
||||
void clear();
|
||||
size_t size() const;
|
||||
std::vector<std::shared_ptr<kc::FileContext>> get() const;
|
||||
[[nodiscard]] size_t size() const;
|
||||
[[nodiscard]] std::vector<std::shared_ptr<kc::FileContext>> get() const;
|
||||
void parse_all();
|
||||
std::string get_root_path() const;
|
||||
[[nodiscard]] std::string get_root_path() const;
|
||||
|
||||
std::unordered_map<std::string, std::vector<std::shared_ptr<kc::FileEntry>>> tag_map;
|
||||
|
||||
|
@ -2,25 +2,24 @@
|
||||
|
||||
namespace kc {
|
||||
|
||||
Link::Link(std::string original)
|
||||
Link::Link(const std::string &original)
|
||||
{
|
||||
original_form = std::regex_replace(original, std::regex("%20"), " ");
|
||||
|
||||
auto opening_display = original_form.find('[');
|
||||
auto closing_display = original_form.find(']', opening_display);
|
||||
const auto opening_display = original_form.find('[');
|
||||
const auto closing_display = original_form.find(']', opening_display);
|
||||
|
||||
display = original_form.substr(opening_display + 1, closing_display - opening_display - 1);
|
||||
|
||||
auto opening_link = closing_display + 1;
|
||||
auto closing_link = original_form.rfind(')');
|
||||
const auto opening_link = closing_display + 1;
|
||||
const auto closing_link = original_form.rfind(')');
|
||||
|
||||
link = original_form.substr(opening_link + 1, closing_link - opening_link - 1);
|
||||
|
||||
external = link.starts_with("http");
|
||||
|
||||
auto sublink_pos = original_form.find('#', opening_link);
|
||||
|
||||
if(sublink_pos != std::string::npos)
|
||||
if(const auto sublink_pos = original_form.find('#', opening_link);
|
||||
sublink_pos != std::string::npos)
|
||||
{
|
||||
sublink = original_form.substr(sublink_pos + 1, closing_link - sublink_pos - 1);
|
||||
link = original_form.substr(opening_link + 1, sublink_pos - opening_link - 1);
|
||||
|
@ -12,9 +12,9 @@ class Link {
|
||||
std::string display;
|
||||
std::string link;
|
||||
std::string sublink;
|
||||
bool is_external() const;
|
||||
[[nodiscard]] bool is_external() const;
|
||||
|
||||
Link(std::string original);
|
||||
explicit Link(const std::string &original);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -15,19 +15,18 @@ std::vector<kc::FileLinkStateResult> validate_links(const std::vector<std::share
|
||||
|
||||
auto invalid_counter = 0;
|
||||
|
||||
for (auto context : contexts)
|
||||
for (const auto& context : contexts)
|
||||
{
|
||||
if (context->links.size() > 0)
|
||||
if (!context->links.empty())
|
||||
{
|
||||
for (auto link: context->links)
|
||||
for (const auto& link: context->links)
|
||||
{
|
||||
if(!link.is_external()) {
|
||||
|
||||
auto composed = context->abs_path(link);
|
||||
|
||||
auto entry = fs::directory_entry(composed);
|
||||
|
||||
if(!entry.exists())
|
||||
if(auto entry = fs::directory_entry(composed);
|
||||
!entry.exists())
|
||||
{
|
||||
print_and_log("Invalid link: " + std::string(context->file_entry->file_entry.path()) + " -> " + link.original_form);
|
||||
invalid_counter++;
|
||||
|
Loading…
Reference in New Issue
Block a user