65 return arg.size() > 0 &&
arg[0] ==
'-' ?
arg.substr(1) :
arg;
88 const std::string &value) {
96 if (key.substr(0, 2) ==
"no") {
100 LogPrintf(
"Warning: parsed potentially confusing double-negative "
121 "Negating of -%s is meaningless and therefore forbidden", key);
139 if (m_network.empty()) {
140 return std::set<std::string>{};
145 return std::set<std::string>{};
149 if (OnlyHasDefaultSectionSetting(
m_settings, m_network,
179 if (
is_index != std::string::npos) {
195 if (key.length() > 1 && key[1] ==
'-') {
202 std::string &
error) {
206 for (
int i = 1; i <
argc; i++) {
207 std::string key(
argv[i]);
214 if (key.substr(0, 5) ==
"-psn_") {
246 m_settings.command_line_options[key].push_back(value);
255 "-includeconf cannot be used from commandline; -includeconf=" +
263std::optional<unsigned int>
269 return search->second.m_flags;
286 return result.has_filename() ? result : result.parent_path();
301 if (!fs::is_directory(path)) {
326 if (!datadir.empty()) {
328 if (!fs::is_directory(path)) {
372 std::vector<std::string> result;
374 result.push_back(value.isFalse() ?
"0"
375 : value.isTrue() ?
"1"
391 std::vector<std::string>
errors;
447 std::string key =
setting.first;
462 throw std::logic_error(
"Attempt to write settings file when dynamic "
463 "settings are disabled.");
474 {
strprintf(
"Failed renaming settings file %s to %s\n",
499std::optional<std::string>
609 const std::vector<std::string> &values) {
613 for (
const std::string &s : values) {
624 if (
eq_index == std::string::npos) {
656 std::string
usage =
"";
720 if (
arg.second.m_help_param.empty()) {
738 args.
AddArg(
"-?",
"Print this help message and exit",
false,
748 return std::string(message) + std::string(
"\n\n");
752 const std::string &message) {
754 std::string(
"\n") + std::string(
msgIndent,
' ') +
776 return pathRet /
"Library/Application Support/Bitcoin";
786 return datadir.empty() || fs::is_directory(
fs::absolute(datadir));
811 throw std::runtime_error(
"Invalid combination of -regtest, -testnet "
812 "and -chain. Can use at most one.");
836std::vector<util::SettingsValue>
845 const std::map<std::string, std::vector<util::SettingsValue>> &args)
const {
847 for (
const auto &
arg : args) {
848 for (
const auto &value :
arg.second) {
874WinCmdLineArgs::WinCmdLineArgs() {
876 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>
utf8_cvt;
879 for (
int i = 0; i <
argc; i++) {
881 argv[i] = &*args[i].begin();
886WinCmdLineArgs::~WinCmdLineArgs() {
890std::pair<int, char **> WinCmdLineArgs::get() {
bool HelpRequested(const ArgsManager &args)
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
fs::path GetDefaultDataDir()
static const int msgIndent
bool CheckValid(const std::string &key, const util::SettingsValue &val, unsigned int flags, std::string &error)
Check settings value validity according to flags.
static void SaveErrors(const std::vector< std::string > errors, std::vector< std::string > *error_out)
std::optional< std::string > SettingToString(const util::SettingsValue &value)
const char *const BITCOIN_SETTINGS_FILENAME
bool ParseKeyValue(std::string &key, std::string &val)
std::optional< bool > SettingToBool(const util::SettingsValue &value)
bool CheckDataDirOption(const ArgsManager &args)
static const int screenWidth
static std::string SettingName(const std::string &arg)
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
const char *const BITCOIN_CONF_FILENAME
util::SettingsValue InterpretOption(std::string §ion, std::string &key, const std::string &value)
Interpret -nofoo as if the user supplied -foo=0.
static bool InterpretBool(const std::string &strValue)
Interpret a string argument as a boolean.
static const int optIndent
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
std::optional< int64_t > SettingToInt(const util::SettingsValue &value)
bool CheckValid(const std::string &key, const util::SettingsValue &val, unsigned int flags, std::string &error)
Check settings value validity according to flags.
const char *const BITCOIN_SETTINGS_FILENAME
bool ParseKeyValue(std::string &key, std::string &val)
bool SettingToBool(const util::SettingsValue &, bool)
int64_t SettingToInt(const util::SettingsValue &, int64_t)
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
const char *const BITCOIN_CONF_FILENAME
util::SettingsValue InterpretOption(std::string §ion, std::string &key, const std::string &value)
Interpret -nofoo as if the user supplied -foo=0.
fs::path GetConfigFile(const ArgsManager &args, const fs::path &configuration_file_path)
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
std::string SettingToString(const util::SettingsValue &, const std::string &)
const CBaseChainParams & BaseParams()
Return the currently selected parameters.
const fs::path & GetDataDirBase() const
Get data directory path.
const std::set< std::string > GetUnsuitableSectionOnlyArgs() const
Log warnings for options in m_section_only_args when they are specified in the default section but no...
const fs::path & GetBlocksDirPath() const
Get blocks directory path.
bool IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
bool ReadSettingsFile(std::vector< std::string > *errors=nullptr)
Read settings file.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
bool InitSettings(std::string &error)
Read and update settings file with saved settings.
bool ParseParameters(int argc, const char *const argv[], std::string &error)
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
util::SettingsValue GetPersistentSetting(const std::string &name) const
Get current setting from config file or read/write settings file, ignoring nonpersistent command line...
std::optional< unsigned int > GetArgFlags(const std::string &name) const
Return Flags for known arg.
void EnsureDataDir() const
If datadir does not exist, create it along with wallets/ subdirectory(s).
bool GetSettingsPath(fs::path *filepath=nullptr, bool temp=false, bool backup=false) const
Get settings file path, or return false if read-write settings were disabled with -nosettings.
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
void SelectConfigNetwork(const std::string &network)
Select the network in use.
std::string GetHelpMessage() const
Get the help string.
void ForceSetMultiArg(const std::string &strArg, const std::vector< std::string > &values)
This function is only used for testing purpose so so we should not worry about element uniqueness and...
void ClearPathCache()
Clear cached directory paths.
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr, bool backup=false) const
Write settings file or backup settings file.
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
const fs::path & GetDataDir(bool net_specific) const
Get data directory path.
void logArgsPrefix(const std::string &prefix, const std::string §ion, const std::map< std::string, std::vector< util::SettingsValue > > &args) const
fs::path GetConfigFilePath() const
Return config file path (read-only)
void ClearForcedArg(const std::string &strArg)
Remove a forced arg setting, used only in testing.
std::vector< util::SettingsValue > GetSettingsList(const std::string &arg) const
Get list of setting values.
void LogArgs() const
Log the config file options and the command line arguments, useful for troubleshooting.
bool UseDefaultSection(const std::string &arg) const EXCLUSIVE_LOCKS_REQUIRED(cs_args)
Returns true if settings values from the default section should be used, depending on the current net...
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
util::SettingsValue GetSetting(const std::string &arg) const
Get setting value.
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
fs::path GetPathArg(std::string arg, const fs::path &default_value={}) const
Return path argument or default value.
const std::list< SectionInfo > GetUnrecognizedSections() const
Log warnings for unrecognized section names in the config file.
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
static const std::string REGTEST
static const std::string TESTNET
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
void push_back(UniValue val)
const std::string & get_str() const
const std::string & getValStr() const
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
bool RenameOver(fs::path src, fs::path dest)
bool error(const char *fmt, const Args &...args)
static path absolute(const path &p)
static bool create_directories(const std::filesystem::path &p)
Create directory (and if necessary its parents), unless the leaf directory already exists or is a sym...
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to byte string.
static path PathFromString(const std::string &string)
Convert byte string to path object.
fs::path AbsPathJoin(const fs::path &base, const fs::path &path)
Helper function for joining two paths.
std::vector< SettingsValue > GetSettingsList(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config)
Get combined setting value similar to GetSetting(), except if setting was specified multiple times,...
SettingsValue GetSetting(const Settings &settings, const std::string §ion, const std::string &name, bool ignore_default_section_config, bool ignore_nonpersistent, bool get_chain_name)
Get settings value from combined sources: forced settings, command line arguments,...
bool ReadSettings(const fs::path &path, std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Read settings file.
bool WriteSettings(const fs::path &path, const std::map< std::string, SettingsValue > &values, std::vector< std::string > &errors)
Write settings file.
auto FindKey(Map &&map, Key &&key) -> decltype(&map.at(key))
Map lookup helper.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
std::string FormatParagraph(const std::string &in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line.
std::string ToLower(const std::string &str)
Returns the lowercase equivalent of the given string.
int atoi(const std::string &str)
int64_t atoi64(const std::string &str)
auto Join(const std::vector< T > &list, const BaseType &separator, UnaryOp unary_op) -> decltype(unary_op(list.at(0)))
Join a list of items.
Accessor for list of settings that skips negated values when iterated over.