Track negated arguments in the argument paser.

This commit adds tracking for negated arguments. This change will be used in a
future commit that allows disabling the debug.log file using -nodebuglogfile.
This commit is contained in:
Evan Klitzke
2018-03-21 19:24:17 -07:00
parent 4f872b2450
commit f7683cba7b
3 changed files with 110 additions and 40 deletions

View File

@@ -25,6 +25,7 @@
#include <map>
#include <stdint.h>
#include <string>
#include <unordered_set>
#include <vector>
#include <boost/signals2/signal.hpp>
@@ -224,6 +225,8 @@ protected:
mutable CCriticalSection cs_args;
std::map<std::string, std::string> mapArgs;
std::map<std::string, std::vector<std::string>> mapMultiArgs;
std::unordered_set<std::string> m_negated_args;
public:
void ParseParameters(int argc, const char*const argv[]);
void ReadConfigFile(const std::string& confPath);
@@ -244,6 +247,15 @@ public:
*/
bool IsArgSet(const std::string& strArg) const;
/**
* Return true if the argument was originally passed as a negated option,
* i.e. -nofoo.
*
* @param strArg Argument to get (e.g. "-foo")
* @return true if the argument was passed negated
*/
bool IsArgNegated(const std::string& strArg) const;
/**
* Return string argument or default value
*
@@ -292,6 +304,11 @@ public:
// Forces an arg setting. Called by SoftSetArg() if the arg hasn't already
// been set. Also called directly in testing.
void ForceSetArg(const std::string& strArg, const std::string& strValue);
private:
// Munge -nofoo into -foo=0 and track the value as negated.
void InterpretNegatedOption(std::string &key, std::string &val);
};
extern ArgsManager gArgs;