refactor
This commit is contained in:
@@ -146,9 +146,12 @@ auto load_config(std::string &cfg_file) -> app_config {
|
||||
}
|
||||
|
||||
if (not utils::file::directory{cfg_dir}.create_directory()) {
|
||||
throw std::runtime_error(fmt::format("failed to create config dir|{}|{}",
|
||||
throw utils::error::create_exception(
|
||||
function_name, {
|
||||
"failed to create config dir",
|
||||
cfg_dir,
|
||||
utils::get_last_error_code()));
|
||||
std::to_string(utils::get_last_error_code()),
|
||||
});
|
||||
}
|
||||
|
||||
cfg_file = utils::path::combine(cfg_dir, {"monitarr.json"});
|
||||
@@ -161,6 +164,17 @@ auto load_config(std::string &cfg_file) -> app_config {
|
||||
cfg.save(cfg_file);
|
||||
}
|
||||
|
||||
auto iter = std::ranges::adjacent_find(
|
||||
cfg.server_list,
|
||||
[](auto &&srv1, auto &&srv2) -> bool { return srv1.id == srv2.id; });
|
||||
if (iter != cfg.server_list.end()) {
|
||||
throw utils::error::create_exception(function_name,
|
||||
{
|
||||
"duplicate server found",
|
||||
iter->id,
|
||||
});
|
||||
}
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,8 +74,12 @@ void data_db::open(std::string_view data_dir) {
|
||||
auto status = rocksdb::TransactionDB::Open(
|
||||
options, rocksdb::TransactionDBOptions{}, db_path, &ptr);
|
||||
if (not status.ok()) {
|
||||
throw std::runtime_error(fmt::format("failed to open database|{}|{}",
|
||||
db_path, status.ToString()));
|
||||
throw utils::error::create_exception(function_name,
|
||||
{
|
||||
"failed to open database",
|
||||
db_path,
|
||||
status.ToString(),
|
||||
});
|
||||
}
|
||||
|
||||
db_ = std::shared_ptr<rocksdb::TransactionDB>(ptr);
|
||||
|
||||
@@ -130,15 +130,20 @@ static void check_server(const server_cfg &server, data_db &state_db) {
|
||||
}
|
||||
|
||||
[[nodiscard]] static auto load_db() -> data_db {
|
||||
MONITARR_USES_FUNCTION_NAME();
|
||||
|
||||
auto data_dir = utils::get_environment_variable("MONITARR_DATA_DIR");
|
||||
if (data_dir.empty()) {
|
||||
data_dir = utils::path::combine(".", {"data"});
|
||||
}
|
||||
|
||||
if (not utils::file::directory{data_dir}.create_directory()) {
|
||||
throw std::runtime_error(fmt::format("failed to create data dir|{}",
|
||||
throw utils::error::create_exception(
|
||||
function_name, {
|
||||
"failed to create data dir",
|
||||
data_dir,
|
||||
utils::get_last_error_code()));
|
||||
std::to_string(utils::get_last_error_code()),
|
||||
});
|
||||
}
|
||||
|
||||
data_db state_db{};
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
#include "usage_cmd.hpp"
|
||||
|
||||
#include "utils/error.hpp"
|
||||
|
||||
namespace monitarr {
|
||||
auto usage_cmd() -> int {
|
||||
fmt::println("usage:");
|
||||
fmt::println(" monitarr -b -i <index> -id <record id>");
|
||||
fmt::println(" blocklist and search record id at configuration index");
|
||||
fmt::println(" monitarr -c");
|
||||
fmt::println(" display configuration");
|
||||
fmt::println(" monitarr -l -i <index>");
|
||||
fmt::println(" display server queue at configuration index");
|
||||
fmt::println(" monitarr -r");
|
||||
fmt::println(" run monitarr server");
|
||||
fmt::println(" monitarr -s -i <index> -id <record id>");
|
||||
fmt::println(" show record id details at configuration index");
|
||||
MONITARR_USES_FUNCTION_NAME();
|
||||
|
||||
utils::error::handle_info(
|
||||
function_name,
|
||||
"\n\nusage:\n"
|
||||
" monitarr -b -i <index> -id <record id>\n"
|
||||
" blocklist and search record id at configuration index\n"
|
||||
" monitarr -c\n"
|
||||
" display configuration\n"
|
||||
" monitarr -l -i <index>\n"
|
||||
" display server queue at configuration index\n"
|
||||
" monitarr -r\n"
|
||||
" run monitarr server\n"
|
||||
" monitarr -s -i <index> -id <record id>\n"
|
||||
" show record id details at configuration index\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user