about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-06-07T14·49+0200
committerEelco Dolstra <edolstra@gmail.com>2017-06-07T14·49+0200
commitaa952d5f0bc623a1584f2d589209f586e594c75f (patch)
tree685780bc5155600f5f27f04c09302e2644236cad
parentb8283773bd64d7da6859ed520ee19867742a03ba (diff)
nix: Add --help-config flag
-rw-r--r--src/libutil/args.hh2
-rw-r--r--src/libutil/config.hh10
-rw-r--r--src/nix/main.cc20
3 files changed, 30 insertions, 2 deletions
diff --git a/src/libutil/args.hh b/src/libutil/args.hh
index ac12f8be633a..f70bb7823dc0 100644
--- a/src/libutil/args.hh
+++ b/src/libutil/args.hh
@@ -41,7 +41,7 @@ protected:
 
     virtual bool processFlag(Strings::iterator & pos, Strings::iterator end);
 
-    void printFlags(std::ostream & out);
+    virtual void printFlags(std::ostream & out);
 
     /* Positional arguments. */
     struct ExpectedArg
diff --git a/src/libutil/config.hh b/src/libutil/config.hh
index 2ca643fe0e71..994eab911707 100644
--- a/src/libutil/config.hh
+++ b/src/libutil/config.hh
@@ -31,6 +31,8 @@ class Config
 {
     friend class AbstractSetting;
 
+public:
+
     struct SettingData
     {
         bool isAlias;
@@ -40,7 +42,11 @@ class Config
         { }
     };
 
-    std::map<std::string, SettingData> _settings;
+    typedef std::map<std::string, SettingData> Settings;
+
+private:
+
+    Settings _settings;
 
     StringMap initials;
 
@@ -58,6 +64,8 @@ public:
 
     StringMap getSettings(bool overridenOnly = false);
 
+    const Settings & _getSettings() { return _settings; }
+
     void applyConfigFile(const Path & path, bool fatal = false);
 
     void resetOverriden();
diff --git a/src/nix/main.cc b/src/nix/main.cc
index f83843415e3b..ea6838cd76c9 100644
--- a/src/nix/main.cc
+++ b/src/nix/main.cc
@@ -21,10 +21,30 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
             throw Exit();
         });
 
+        mkFlag(0, "help-config", "show configuration options", [=]() {
+            std::cout << "The following configuration options are available:\n\n";
+            Table2 tbl;
+            for (const auto & s : settings._getSettings())
+                if (!s.second.isAlias)
+                    tbl.emplace_back(s.first, s.second.setting->description);
+            printTable(std::cout, tbl);
+            throw Exit();
+        });
+
         mkFlag(0, "version", "show version information", std::bind(printVersion, programName));
 
         settings.convertToArgs(*this);
     }
+
+    void printFlags(std::ostream & out) override
+    {
+        Args::printFlags(out);
+        std::cout <<
+            "\n"
+            "In addition, most configuration settings can be overriden using ‘--<name> <value>’.\n"
+            "Boolean settings can be overriden using ‘--<name>’ or ‘--no-<name>’. See ‘nix\n"
+            "--help-config’ for a list of configuration settings.\n";
+    }
 };
 
 void mainWrapped(int argc, char * * argv)