Bitcoin ABC 0.26.3
P2P Digital Currency
|
#include <common/args.h>
#include <chainparamsbase.h>
#include <logging.h>
#include <sync.h>
#include <tinyformat.h>
#include <univalue.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <util/settings.h>
#include <util/strencodings.h>
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <filesystem>
#include <map>
#include <optional>
#include <stdexcept>
#include <string>
Go to the source code of this file.
Namespaces | |
namespace | common |
Functions | |
static bool | InterpretBool (const std::string &strValue) |
Interpret a string argument as a boolean. | |
static std::string | SettingName (const std::string &arg) |
util::SettingsValue | InterpretOption (std::string §ion, std::string &key, const std::string &value) |
Interpret -nofoo as if the user supplied -foo=0. | |
bool | CheckValid (const std::string &key, const util::SettingsValue &val, unsigned int flags, std::string &error) |
Check settings value validity according to flags. | |
bool | ParseKeyValue (std::string &key, std::string &val) |
static void | SaveErrors (const std::vector< std::string > errors, std::vector< std::string > *error_out) |
std::optional< std::string > | SettingToString (const util::SettingsValue &value) |
std::string | SettingToString (const util::SettingsValue &value, const std::string &strDefault) |
std::optional< int64_t > | SettingToInt (const util::SettingsValue &value) |
int64_t | SettingToInt (const util::SettingsValue &value, int64_t nDefault) |
std::optional< bool > | SettingToBool (const util::SettingsValue &value) |
bool | SettingToBool (const util::SettingsValue &value, bool fDefault) |
bool | HelpRequested (const ArgsManager &args) |
void | SetupHelpOptions (ArgsManager &args) |
Add help options to the args manager. | |
std::string | HelpMessageGroup (const std::string &message) |
Format a string to be used as group of options in help messages. | |
std::string | HelpMessageOpt (const std::string &option, const std::string &message) |
Format a string to be used as option description in help messages. | |
fs::path | GetDefaultDataDir () |
bool | CheckDataDirOption (const ArgsManager &args) |
Variables | |
const char *const | BITCOIN_CONF_FILENAME = "bitcoin.conf" |
const char *const | BITCOIN_SETTINGS_FILENAME = "settings.json" |
ArgsManager | gArgs |
static const int | screenWidth = 79 |
static const int | optIndent = 2 |
static const int | msgIndent = 7 |
bool CheckDataDirOption | ( | const ArgsManager & | args | ) |
bool CheckValid | ( | const std::string & | key, |
const util::SettingsValue & | val, | ||
unsigned int | flags, | ||
std::string & | error | ||
) |
Check settings value validity according to flags.
TODO: Add more meaningful error checks here in the future See "here's how the flags are meant to behave" in https://github.com/bitcoin/bitcoin/pull/16097#issuecomment-514627823
Definition at line 117 of file args.cpp.
fs::path GetDefaultDataDir | ( | ) |
std::string HelpMessageGroup | ( | const std::string & | message | ) |
std::string HelpMessageOpt | ( | const std::string & | option, |
const std::string & | message | ||
) |
Format a string to be used as option description in help messages.
option | Option message (e.g. "-rpcuser=<user>") |
message | Option description (e.g. "Username for JSON-RPC connections") |
Definition at line 751 of file args.cpp.
bool HelpRequested | ( | const ArgsManager & | args | ) |
Interpret a string argument as a boolean.
The definition of atoi() requires that non-numeric string values like "foo", return 0. This means that if a user unintentionally supplies a non-integer argument here, the return value is always false. This means that -foo=false does what the user probably expects, but -foo=true is well defined but does not do what they probably expected.
The return value of atoi() is undefined when given input not representable as an int. On most systems this means string value between "-2147483648" and "2147483647" are well defined (this method will return true). Setting -txindex=2147483648 on most systems, however, is probably undefined.
For a more extensive discussion of this topic (and a wide range of opinions on the Right Way to change this code), see PR12713.
Definition at line 57 of file args.cpp.
util::SettingsValue InterpretOption | ( | std::string & | section, |
std::string & | key, | ||
const std::string & | value | ||
) |
Interpret -nofoo as if the user supplied -foo=0.
This method also tracks when the -no form was supplied, and if so, checks whether there was a double-negative (-nofoo=0 -> -foo=1).
If there was not a double negative, it removes the "no" from the key and returns false.
If there was a double negative, it removes "no" from the key, and returns true.
If there was no "no", it returns the string value untouched.
Where an option was negated can be later checked using the IsArgNegated() method. One use case for this is to have a way to disable options that are not normally boolean (e.g. using -nodebuglogfile to request that debug log output is not sent to any file at all).
Definition at line 87 of file args.cpp.
bool ParseKeyValue | ( | std::string & | key, |
std::string & | val | ||
) |
|
static |
|
static |
std::optional< bool > SettingToBool | ( | const util::SettingsValue & | value | ) |
bool SettingToBool | ( | const util::SettingsValue & | value, |
bool | fDefault | ||
) |
std::optional< int64_t > SettingToInt | ( | const util::SettingsValue & | value | ) |
int64_t SettingToInt | ( | const util::SettingsValue & | value, |
int64_t | nDefault | ||
) |
std::optional< std::string > SettingToString | ( | const util::SettingsValue & | value | ) |
std::string SettingToString | ( | const util::SettingsValue & | value, |
const std::string & | strDefault | ||
) |
void SetupHelpOptions | ( | ArgsManager & | args | ) |
const char* const BITCOIN_SETTINGS_FILENAME = "settings.json" |
ArgsManager gArgs |