mirror of
https://github.com/NotAShelf/Hyprdoctor.git
synced 2024-11-22 05:10:48 +00:00
add --verbose
for a little more debugging info
This commit is contained in:
parent
1ebaab6294
commit
03929055f8
4 changed files with 59 additions and 29 deletions
5
Makefile
5
Makefile
|
@ -4,13 +4,14 @@ TARGET = Hyprdoctor
|
|||
SRCS = main.cpp src/utils/environment.cpp src/utils/file_parser.cpp src/utils/json_parser.cpp
|
||||
OBJS = $(SRCS:.cpp=.o)
|
||||
|
||||
all: $(TARGET);
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) -o $@ $^
|
||||
$(CXX) $(CXXFLAGS) -o $@ $^ -lboost_program_options
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
run:
|
||||
./$(TARGET)
|
||||
|
||||
|
|
40
main.cpp
40
main.cpp
|
@ -1,23 +1,45 @@
|
|||
|
||||
#include "src/utils/environment.h"
|
||||
#include "src/utils/file_parser.h"
|
||||
#include "src/utils/json_parser.h"
|
||||
#include <boost/program_options.hpp>
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
namespace po = boost::program_options;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
po::options_description desc("Allowed options");
|
||||
desc.add_options()("help", "Produce help message")("verbose",
|
||||
"Enable verbose output");
|
||||
|
||||
po::variables_map vm;
|
||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||
po::notify(vm);
|
||||
|
||||
if (vm.count("help")) {
|
||||
std::cout << desc << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *envVar = getEnvVar("HYPRLAND_INSTANCE_SIGNATURE");
|
||||
|
||||
// if --verbose flag is set, print the environment variable
|
||||
if (vm.count("verbose")) {
|
||||
std::cout << "HYPRLAND_INSTANCE_SIGNATURE: " << envVar << std::endl;
|
||||
}
|
||||
|
||||
// try opening the log file
|
||||
try {
|
||||
std::string filePath = "/tmp/hypr/" + std::string(envVar);
|
||||
std::vector<std::string> errLines = readErrLines(filePath);
|
||||
if (envVar != nullptr) {
|
||||
std::string filePath = "/tmp/hypr/" + std::string(envVar);
|
||||
std::vector<std::string> errLines = readErrLines(filePath);
|
||||
|
||||
// associate each error with the issue ID and name
|
||||
std::vector<std::pair<int, std::string>> issues =
|
||||
findErrorsInJsonFiles(errLines, "database");
|
||||
// associate each error with the issue ID and name
|
||||
std::vector<std::pair<int, std::string>> issues =
|
||||
findErrorsInJsonFiles(errLines, "database", vm.count("verbose"));
|
||||
|
||||
for (const auto &[id, name] : issues) {
|
||||
std::cout << "Issue ID: " << id << ", Name: " << name << std::endl;
|
||||
for (const auto &[id, name] : issues) {
|
||||
std::cout << "Issue ID: " << id << ", Name: " << name << std::endl;
|
||||
}
|
||||
}
|
||||
} catch (const std::runtime_error &e) {
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
|
|
|
@ -2,28 +2,34 @@
|
|||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
std::vector<std::pair<int, std::string>>
|
||||
findErrorsInJsonFiles(const std::vector<std::string> &errLines,
|
||||
const std::string &dirPath) {
|
||||
std::vector<std::pair<int, std::string>> issues;
|
||||
const std::string &dirPath, bool verbose) {
|
||||
std::vector<std::pair<int, std::string>> issues;
|
||||
|
||||
for (const auto &entry : std::filesystem::directory_iterator(dirPath)) {
|
||||
std::ifstream file(entry.path());
|
||||
nlohmann::json j;
|
||||
file >> j;
|
||||
for (const auto &entry : std::filesystem::directory_iterator(dirPath)) {
|
||||
if (verbose) {
|
||||
std::cout << "Processing file: " << entry.path() << std::endl;
|
||||
}
|
||||
std::ifstream file(entry.path());
|
||||
nlohmann::json j;
|
||||
file >> j;
|
||||
|
||||
if (j.contains("errors") && j["errors"].is_array()) {
|
||||
for (const auto &error : j["errors"]) {
|
||||
if (std::find(errLines.begin(), errLines.end(), error) !=
|
||||
errLines.end()) {
|
||||
issues.push_back({j["ID"], j["name"]});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (j.contains("errors") && j["errors"].is_array()) {
|
||||
for (const auto &error : j["errors"]) {
|
||||
if (std::find(errLines.begin(), errLines.end(), error) !=
|
||||
errLines.end()) {
|
||||
issues.push_back({j["ID"], j["name"]});
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw std::runtime_error("Invalid JSON file");
|
||||
}
|
||||
}
|
||||
|
||||
return issues;
|
||||
return issues;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#ifndef JSON_PARSER_H
|
||||
#define JSON_PARSER_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
std::vector<std::pair<int, std::string>>
|
||||
findErrorsInJsonFiles(const std::vector<std::string> &errLines,
|
||||
const std::string &dirPath);
|
||||
const std::string &dirPath, bool verbose);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue