nix: Add --help-config flag
This commit is contained in:
		
							parent
							
								
									b8283773bd
								
							
						
					
					
						commit
						aa952d5f0b
					
				
					 3 changed files with 30 additions and 2 deletions
				
			
		| 
						 | 
					@ -41,7 +41,7 @@ protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual bool processFlag(Strings::iterator & pos, Strings::iterator end);
 | 
					    virtual bool processFlag(Strings::iterator & pos, Strings::iterator end);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void printFlags(std::ostream & out);
 | 
					    virtual void printFlags(std::ostream & out);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Positional arguments. */
 | 
					    /* Positional arguments. */
 | 
				
			||||||
    struct ExpectedArg
 | 
					    struct ExpectedArg
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,6 +31,8 @@ class Config
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    friend class AbstractSetting;
 | 
					    friend class AbstractSetting;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    struct SettingData
 | 
					    struct SettingData
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        bool isAlias;
 | 
					        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;
 | 
					    StringMap initials;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -58,6 +64,8 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    StringMap getSettings(bool overridenOnly = false);
 | 
					    StringMap getSettings(bool overridenOnly = false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const Settings & _getSettings() { return _settings; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void applyConfigFile(const Path & path, bool fatal = false);
 | 
					    void applyConfigFile(const Path & path, bool fatal = false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void resetOverriden();
 | 
					    void resetOverriden();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,10 +21,30 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
 | 
				
			||||||
            throw Exit();
 | 
					            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));
 | 
					        mkFlag(0, "version", "show version information", std::bind(printVersion, programName));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        settings.convertToArgs(*this);
 | 
					        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)
 | 
					void mainWrapped(int argc, char * * argv)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue