diff --git a/src/cmd/pr.cpp b/src/cmd/pr.cpp index 37108f0..93bb1a2 100644 --- a/src/cmd/pr.cpp +++ b/src/cmd/pr.cpp @@ -65,7 +65,7 @@ clipp::group pr_command::do_group() int pr_command::do_run() { if (github_token_.empty()) - github_token_ = conf::global_by_name("github_key"); + github_token_ = conf().global().get("github_key"); if (op_ == "pull") return pull(); diff --git a/src/core/conf.cpp b/src/core/conf.cpp index 305d7c8..9d4a715 100644 --- a/src/core/conf.cpp +++ b/src/core/conf.cpp @@ -527,7 +527,7 @@ bool try_qt_location(fs::path& check) fs::path find_qt() { - fs::path p = conf::path_by_name("qt_install"); + fs::path p = conf().paths().qt_install(); if (!p.empty()) { @@ -904,7 +904,7 @@ void make_canonical_path( std::string_view key, const fs::path& default_parent, std::string_view default_dir) { - fs::path p = conf::path_by_name(key); + fs::path p = conf().paths().get(key); if (p.empty()) { @@ -1195,7 +1195,7 @@ void init_options( find_vcvars(); validate_qt(); - this_env::append_to_path(conf::path_by_name("qt_bin")); + this_env::append_to_path(conf().paths().get("qt_bin")); if (!conf().paths().prefix().empty()) make_canonical_path("prefix", ini_prefix.empty() ? fs::current_path() : ini_prefix.parent_path(), ""); diff --git a/src/core/conf.h b/src/core/conf.h index 3453879..daf961b 100644 --- a/src/core/conf.h +++ b/src/core/conf.h @@ -3,6 +3,7 @@ namespace mob { +class conf_section; class conf_global; class conf_prebuilt; class conf_transifex; @@ -10,6 +11,13 @@ class conf_paths; class conf { + // temp + friend class conf_section; + friend class conf_global; + friend class conf_prebuilt; + friend class conf_transifex; + friend class conf_paths; + public: conf_global global(); conf_transifex transifex(); @@ -23,7 +31,6 @@ public: static bool bool_task_option_by_name( const std::vector& task_names, std::string_view name); - static fs::path path_by_name(std::string_view name); static std::string version_by_name(std::string_view name); static fs::path tool_by_name(std::string_view name); @@ -53,34 +60,27 @@ public: static std::vector format_options(); // only in conf.cpp - static std::string get_global( std::string_view section, std::string_view key); - static int get_global_int( - std::string_view section, std::string_view key); - static bool get_global_bool( std::string_view section, std::string_view key); - static void add_global( - std::string_view section, - std::string_view key, std::string_view value); - - static std::string get_for_task( - const std::vector& task_names, + static int get_global_int( std::string_view section, std::string_view key); - static void set_for_task( - std::string_view task_name, std::string_view section, - std::string_view key, std::string_view value); - static void set_global( std::string_view section, std::string_view key, std::string_view value); - static std::string global_by_name(std::string_view name); - static bool bool_global_by_name(std::string_view name); + static void add_global( + std::string_view section, + std::string_view key, std::string_view value); + + static void set_for_task( + std::string_view task_name, std::string_view section, + std::string_view key, std::string_view value); + private: using key_value_map = std::map>; @@ -97,6 +97,17 @@ private: static std::optional find_for_task( std::string_view task_name, std::string_view section, std::string_view key); + + + // temp + static fs::path path_by_name(std::string_view name); + + static std::string get_for_task( + const std::vector& task_names, + std::string_view section, std::string_view key); + + static std::string global_by_name(std::string_view name); + static bool bool_global_by_name(std::string_view name); }; @@ -121,22 +132,22 @@ fs::path make_temp_file(); class conf_section { public: - std::string get(std::string_view key) + std::string get(std::string_view key) const { return conf::get_global(name_, key); } template - T get(std::string_view key); + T get(std::string_view key) const; template <> - bool get(std::string_view key) + bool get(std::string_view key) const { return conf::get_global_bool(name_, key); } template <> - int get(std::string_view key) + int get(std::string_view key) const { return conf::get_global_int(name_, key); } @@ -187,7 +198,7 @@ public: conf_paths(); #define VALUE(NAME) \ - static fs::path NAME() { return conf::path_by_name(#NAME); } + fs::path NAME() const { return get(#NAME); } VALUE(third_party); VALUE(prefix); @@ -210,6 +221,10 @@ public: VALUE(install_pythoncore); VALUE(install_translations); + VALUE(vs); + VALUE(qt_install); + VALUE(qt_bin); + VALUE(pf_x86); VALUE(pf_x64); VALUE(temp_dir); diff --git a/src/tools/tools.cpp b/src/tools/tools.cpp index 2fb5200..ae1dfd9 100644 --- a/src/tools/tools.cpp +++ b/src/tools/tools.cpp @@ -83,12 +83,12 @@ fs::path nasm::binary() fs::path qt::installation_path() { - return conf::path_by_name("qt_install"); + return conf().paths().qt_install(); } fs::path qt::bin_path() { - return conf::path_by_name("qt_bin"); + return conf().paths().get("qt_bin"); } std::string qt::version() @@ -114,7 +114,7 @@ fs::path vs::devenv_binary() fs::path vs::installation_path() { - return conf::path_by_name("vs"); + return conf().paths().get("vs"); } fs::path vs::vswhere()