47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <filesystem>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
/// The CLI's own, global state: where it lives and what the user configured.
|
|
namespace breeze
|
|
{
|
|
|
|
/// $BREEZE_HOME, or ~/.breeze. Holds config.json, the installed CLI versions (cli/), the SDK
|
|
/// snapshots (sdk/) and cached indexes.
|
|
std::filesystem::path breezeHome();
|
|
|
|
/// The keys of config.json. Each can also come from the environment (BREEZE_EDITOR,
|
|
/// BREEZE_SDK_SOURCE, BREEZE_CLI_SOURCE), which wins.
|
|
namespace config
|
|
{
|
|
inline constexpr const char* Editor = "editor";
|
|
inline constexpr const char* SdkSource = "sdkSource";
|
|
inline constexpr const char* CliSource = "cliSource";
|
|
}
|
|
|
|
class GlobalConfig
|
|
{
|
|
public:
|
|
/// Reads config.json (an absent file is an empty configuration).
|
|
static GlobalConfig load();
|
|
|
|
/// The environment's value for the key if set, else the file's.
|
|
[[nodiscard]] std::optional<std::string> effective(const std::string& key) const;
|
|
|
|
/// The file's value only.
|
|
[[nodiscard]] std::optional<std::string> stored(const std::string& key) const;
|
|
|
|
void set(const std::string& key, const std::string& value);
|
|
void erase(const std::string& key);
|
|
void save() const;
|
|
|
|
private:
|
|
nlohmann::json m_data = nlohmann::json::object();
|
|
};
|
|
|
|
}
|