diff options
Diffstat (limited to 'src/libutil/config.hh')
-rw-r--r-- | src/libutil/config.hh | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/libutil/config.hh b/src/libutil/config.hh index 71e31656d..736810bf3 100644 --- a/src/libutil/config.hh +++ b/src/libutil/config.hh @@ -71,9 +71,9 @@ public: /** * Adds the currently known settings to the given result map `res`. * - res: map to store settings in - * - overridenOnly: when set to true only overridden settings will be added to `res` + * - overriddenOnly: when set to true only overridden settings will be added to `res` */ - virtual void getSettings(std::map<std::string, SettingInfo> & res, bool overridenOnly = false) = 0; + virtual void getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly = false) = 0; /** * Parses the configuration in `contents` and applies it @@ -91,7 +91,7 @@ public: /** * Resets the `overridden` flag of all Settings */ - virtual void resetOverriden() = 0; + virtual void resetOverridden() = 0; /** * Outputs all settings to JSON @@ -100,6 +100,12 @@ public: virtual nlohmann::json toJSON() = 0; /** + * Outputs all settings in a key-value pair format suitable to be used as + * `nix.conf` + */ + virtual std::string toKeyValue() = 0; + + /** * Converts settings to `Args` to be used on the command line interface * - args: args to write to * - category: category of the settings @@ -127,7 +133,7 @@ public: MyClass() : Config(readConfigFile("/etc/my-app.conf")) { - std::cout << foo << "\n"; // will print 123 unless overriden + std::cout << foo << "\n"; // will print 123 unless overridden } }; */ @@ -163,12 +169,14 @@ public: void addSetting(AbstractSetting * setting); - void getSettings(std::map<std::string, SettingInfo> & res, bool overridenOnly = false) override; + void getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly = false) override; - void resetOverriden() override; + void resetOverridden() override; nlohmann::json toJSON() override; + std::string toKeyValue() override; + void convertToArgs(Args & args, const std::string & category) override; }; @@ -184,9 +192,7 @@ public: int created = 123; - bool overriden = false; - - void setDefault(const std::string & str); + bool overridden = false; protected: @@ -215,7 +221,7 @@ protected: virtual void convertToArg(Args & args, const std::string & category); - bool isOverriden() const { return overriden; } + bool isOverridden() const { return overridden; } }; /* A setting of type T. */ @@ -245,6 +251,7 @@ public: bool operator !=(const T & v2) const { return value != v2; } void operator =(const T & v) { assign(v); } virtual void assign(const T & v) { value = v; } + void setDefault(const T & v) { if (!overridden) value = v; } void set(const std::string & str, bool append = false) override; @@ -252,7 +259,7 @@ public: virtual void override(const T & v) { - overriden = true; + overridden = true; value = v; } @@ -324,12 +331,14 @@ struct GlobalConfig : public AbstractConfig bool set(const std::string & name, const std::string & value) override; - void getSettings(std::map<std::string, SettingInfo> & res, bool overridenOnly = false) override; + void getSettings(std::map<std::string, SettingInfo> & res, bool overriddenOnly = false) override; - void resetOverriden() override; + void resetOverridden() override; nlohmann::json toJSON() override; + std::string toKeyValue() override; + void convertToArgs(Args & args, const std::string & category) override; struct Register |