Skip to content

Commit b8c069b

Browse files
committed
refactor: Add explicit DISALLOW_NEGATION ArgsManager flag to clarify flag usage
Currently, ALLOW_{INT|BOOL|STRING} flags don't do any real validation, so current uses of these flags are misleading and will also break backwards compatibility whenever these flags are implemented in a future PR (draft PR is #16545). An additional complication is that while these flags don't do any real settings validation, they do affect whether setting negation syntax is allowed. Fix this mess by disabling ALLOW_{INT|BOOL|STRING} flags until they are implemented, and adding an unambiguous DISALLOW_NEGATION flag. This is done in two commits, with this commit adding the DISALLOW_NEGATION flag, and the next commit disabling the ALLOW_{INT|BOOL|STRING} flags.
1 parent 26a50ab commit b8c069b

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/util/system.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static std::optional<util::SettingsValue> InterpretValue(const KeyInfo& key, con
230230
{
231231
// Return negated settings as false values.
232232
if (key.negated) {
233-
if (!(flags & ArgsManager::ALLOW_BOOL)) {
233+
if (flags & ArgsManager::DISALLOW_NEGATION) {
234234
error = strprintf("Negating of -%s is meaningless and therefore forbidden", key.name);
235235
return std::nullopt;
236236
}
@@ -652,6 +652,7 @@ void ArgsManager::AddArg(const std::string& name, const std::string& help, unsig
652652

653653
LOCK(cs_args);
654654
std::map<std::string, Arg>& arg_map = m_available_args[cat];
655+
if ((flags & (ALLOW_ANY | ALLOW_BOOL)) == 0) flags |= DISALLOW_NEGATION; // Temporary, removed in next scripted-diff
655656
auto ret = arg_map.emplace(arg_name, Arg{name.substr(eq_index, name.size() - eq_index), help, flags});
656657
assert(ret.second); // Make sure an insertion actually happened
657658

src/util/system.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,18 @@ struct SectionInfo
158158
class ArgsManager
159159
{
160160
public:
161+
/**
162+
* Flags controlling how config and command line arguments are validated and
163+
* interpreted.
164+
*/
161165
enum Flags : uint32_t {
162-
// Boolean options can accept negation syntax -noOPTION or -noOPTION=1
163-
ALLOW_BOOL = 0x01,
164-
ALLOW_INT = 0x02,
165-
ALLOW_STRING = 0x04,
166-
ALLOW_ANY = ALLOW_BOOL | ALLOW_INT | ALLOW_STRING,
166+
ALLOW_ANY = 0x01, //!< disable validation
167+
ALLOW_BOOL = 0x02, //!< unimplemented, draft implementation in #16545
168+
ALLOW_INT = 0x04, //!< unimplemented, draft implementation in #16545
169+
ALLOW_STRING = 0x08, //!< unimplemented, draft implementation in #16545
170+
ALLOW_LIST = 0x10, //!< unimplemented, draft implementation in #16545
171+
DISALLOW_NEGATION = 0x20, //!< disallow -nofoo syntax
172+
167173
DEBUG_ONLY = 0x100,
168174
/* Some options would cause cross-contamination if values for
169175
* mainnet were used while running on regtest/testnet (or vice-versa).

0 commit comments

Comments
 (0)