#include "toml.hpp"
#include <cstdlib>
#include <filesystem>
#include <iostream>
Go to the source code of this file.
Macros | |
#define | PARENT_LIB "library" |
Macros for parent and field names used in the TOML configuration. | |
#define | PARENT_LIB_FIELD_NAME "name" |
#define | PARENT_LIB_FIELD_DIR "directory" |
#define | PARENT_FTP "ftp" |
#define | PARENT_FTP_FIELD_USER "username" |
#define | PARENT_FTP_FIELD_SALT "salt" |
#define | PARENT_FTP_FIELD_PWD_HASH "password_hash" |
#define | PARENT_DBG "debug" |
#define | PARENT_DBG_FIELD_TAGLIB_PARSER_LOG "taglib_parser_log" |
#define | PARENT_DBG_FIELD_COLORS_PARSER_LOG "colors_parser_log" |
#define | PARENT_DBG_FIELD_KEYBINDS_PARSER_LOG "keybinds_parser_log" |
#define | PARENT_KEYBINDS "keybinds" |
#define | SPECIAL_KEYBIND_ENTER_STR "Enter" |
#define | SPECIAL_KEYBIND_TAB_STR "Tab" |
#define | SPECIAL_KEYBIND_SPACE_STR "Space" |
#define | PARENT_COLORS "colors" |
#define | PARENT_UI "ui" |
#define | CUSTOM_CONFIG_MACRO "INLIMBO_CONFIG_HOME" |
Functions | |
string | getBaseConfigPath () |
Retrieves the path to the configuration directory. | |
string | getConfigPath (string fileName) |
Retrieves the full path to the configuration file. | |
string | getCachePath () |
bool | configFileExists (const string &filePath) |
Checks if the configuration file exists. | |
auto | loadConfig () |
Loads the configuration file. | |
auto | parseTOMLField (string parent, string field) -> string_view |
Parses a string field from the TOML configuration. | |
auto | parseTOMLFieldCustom (const toml::parse_result &custom_config, string parent, string field) -> string_view |
Parses a string field from a custom TOML configuration that is called by the INLIMBO_CONFIG_HOME macro at runtime. | |
auto | parseTOMLFieldInt (string parent, string field) -> int64_t |
Parses an integer field from the TOML configuration. | |
auto | parseTOMLFieldIntCustom (const toml::parse_result &custom_config, string parent, string field) -> int64_t |
Parses an integer field from a custom TOML configuration set by the INLIMBO_CONFIG_HOME macro at runtime. | |
auto | parseTOMLFieldBool (const string &parent, const string &field) -> bool |
Variables | |
auto | config = loadConfig() |
#define CUSTOM_CONFIG_MACRO "INLIMBO_CONFIG_HOME" |
Custom config.toml macro setup
#define PARENT_COLORS "colors" |
Parent section for color settings
#define PARENT_DBG "debug" |
Parent section for debug settings
#define PARENT_DBG_FIELD_COLORS_PARSER_LOG "colors_parser_log" |
#define PARENT_DBG_FIELD_KEYBINDS_PARSER_LOG "keybinds_parser_log" |
#define PARENT_DBG_FIELD_TAGLIB_PARSER_LOG "taglib_parser_log" |
Field for debug parser log setting
#define PARENT_FTP "ftp" |
Parent section for FTP settings
#define PARENT_FTP_FIELD_PWD_HASH "password_hash" |
Field for FTP password hash
#define PARENT_FTP_FIELD_SALT "salt" |
Field for FTP salt
#define PARENT_FTP_FIELD_USER "username" |
Field for FTP username
#define PARENT_KEYBINDS "keybinds" |
Parent section for keybinds
#define PARENT_LIB "library" |
Macros for parent and field names used in the TOML configuration.
These macros represent the sections and fields in the TOML configuration file. Parent section for library settings
#define PARENT_LIB_FIELD_DIR "directory" |
Field for the library directory
#define PARENT_LIB_FIELD_NAME "name" |
Field for the library name
#define PARENT_UI "ui" |
Parent section for ui settings
#define SPECIAL_KEYBIND_ENTER_STR "Enter" |
Special keybind for Enter
#define SPECIAL_KEYBIND_SPACE_STR "Space" |
Special keybind for Space
#define SPECIAL_KEYBIND_TAB_STR "Tab" |
Special keybind for Tab
bool configFileExists | ( | const string & | filePath | ) |
Checks if the configuration file exists.
This function checks if the config.toml
file exists at the given file path.
filePath | The path to the configuration file. |
true
if the file exists, otherwise false
. string getBaseConfigPath | ( | ) |
Retrieves the path to the configuration directory.
By default, this function uses the HOME environment variable to determine the user's home directory. However, it checks for the presence of a INLIMBO_CONFIG_HOME
environment variable first, which can override the default location. This allows for custom configuration paths during testing.
std::runtime_error | If the HOME environment variable is not found and no custom path is provided. |
string getCachePath | ( | ) |
< Exit gracefully if the HOME environment variable is not set.
string getConfigPath | ( | string | fileName | ) |
Retrieves the full path to the configuration file.
This constructs the full path to a specific configuration file.
fileName | The name of the configuration file (e.g., "config.toml"). |
auto loadConfig | ( | ) |
Loads the configuration file.
This function loads the config.toml
file and parses it using the toml
library. If the file does not exist, the program exits gracefully with an error message.
toml::parse_result
object representing the parsed configuration. std::runtime_error | If the configuration file does not exist or cannot be parsed. |
auto parseTOMLField | ( | string | parent, |
string | field ) -> string_view |
Parses a string field from the TOML configuration.
This function retrieves the value of a specific field within a parent section of the TOML configuration. If the field is not found, it returns an empty string view.
parent | The parent section name (e.g., "library"). |
field | The field name within the parent section (e.g., "name"). |
< If the field is not found, return an empty string view.
auto parseTOMLFieldBool | ( | const string & | parent, |
const string & | field ) -> bool |
auto parseTOMLFieldCustom | ( | const toml::parse_result & | custom_config, |
string | parent, | ||
string | field ) -> string_view |
Parses a string field from a custom TOML configuration that is called by the INLIMBO_CONFIG_HOME macro at runtime.
This function retrieves the value of a specific field within a parent section of the TOML configuration. If the field is not found, it returns an empty string view.
parent | The parent section name (e.g., "library"). |
field | The field name within the parent section (e.g., "name"). |
< If the field is not found, return an empty string view.
auto parseTOMLFieldInt | ( | string | parent, |
string | field ) -> int64_t |
Parses an integer field from the TOML configuration.
This function retrieves the value of a specific field as an integer from the TOML configuration. If the field is not found, it returns -1 as a default value.
parent | The parent section name (e.g., "ftp"). |
field | The field name within the parent section (e.g., "username"). |
< If the field is not found, return -1 as default.
auto parseTOMLFieldIntCustom | ( | const toml::parse_result & | custom_config, |
string | parent, | ||
string | field ) -> int64_t |
Parses an integer field from a custom TOML configuration set by the INLIMBO_CONFIG_HOME macro at runtime.
This function retrieves the value of a specific field as an integer from the TOML configuration. If the field is not found, it returns -1 as a default value.
parent | The parent section name (e.g., "ftp"). |
field | The field name within the parent section (e.g., "username"). |
< If the field is not found, return -1 as default.
auto config = loadConfig() |
Parse the configuration file during the initialization