Skip to content

Instantly share code, notes, and snippets.

@LnL7
Created September 18, 2020 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LnL7/7f2e2d67d3acfdf25811f9c4391db09c to your computer and use it in GitHub Desktop.
Save LnL7/7f2e2d67d3acfdf25811f9c4391db09c to your computer and use it in GitHub Desktop.
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index aa694577d..504ae6ebd 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -207,6 +207,16 @@ std::string listLogFormats()
return res;
}
+LogFormatSetting::LogFormatSetting(Config * options,
+ LogFormat def,
+ const std::string & name,
+ const std::string & description,
+ const std::set<std::string> & aliases)
+ : BaseSetting<LogFormat>(def, name, fmt("%s Valid options are: %s.", description, listLogFormats()), aliases)
+{
+ options->addSetting(this);
+}
+
template<> void BaseSetting<LogFormat>::set(const std::string & str)
{
if (str == "raw") value = LogFormat::raw;
@@ -245,7 +255,7 @@ template<> void BaseSetting<LogFormat>::convertToArg(Args & args, const std::str
void setLogFormat(const LogFormat & logFormat)
{
- settings.logFormat = logFormat;
+ settings.logFormat.assign(logFormat);
createDefaultLogger();
}
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index 50bc496b0..cfae2c0a4 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -13,10 +13,17 @@
namespace nix {
-std::string listLogFormats();
-
typedef enum { smEnabled, smRelaxed, smDisabled } SandboxMode;
+struct LogFormatSetting : public BaseSetting<LogFormat>
+{
+ LogFormatSetting(Config * options,
+ LogFormat def,
+ const std::string & name,
+ const std::string & description,
+ const std::set<std::string> & aliases = {});
+};
+
struct MaxBuildJobsSetting : public BaseSetting<unsigned int>
{
MaxBuildJobsSetting(Config * options,
@@ -887,8 +894,7 @@ public:
// FIXME: default shows as "3", but should show as "bar", due to the default
// being an enum variant
- Setting<LogFormat> logFormat{this, LogFormat::bar, "log-format",
- fmt("Default build output logging format. Valid options are: %s.", listLogFormats())};
+ LogFormatSetting logFormat{this, LogFormat::bar, "log-format", "Default build output logging format"};
Logger* makeDefaultLogger();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment