5#ifndef BITCOIN_COMMON_ARGS_H
6#define BITCOIN_COMMON_ARGS_H
33 const fs::path &configuration_file_path);
36 std::optional<std::string> &val);
48 bool net_specific =
true);
52 return c ==
'-' || c ==
'/';
87std::optional<util::SettingsValue>
150 std::map<OptionsCategory, std::map<std::string, Arg>>
158 const std::string &filepath,
160 bool ignore_invalid_keys =
false);
183 std::vector<util::SettingsValue>
202 bool ignore_invalid_keys =
false);
252 std::vector<std::string>
GetArgs(
const std::string &strArg)
const;
260 bool IsArgSet(
const std::string &strArg)
const;
278 std::string
GetArg(
const std::string &strArg,
279 const std::string &strDefault)
const;
280 std::optional<std::string>
GetArg(
const std::string &strArg)
const;
295 const fs::path &default_value = {})
const;
304 int64_t
GetIntArg(
const std::string &strArg, int64_t nDefault)
const;
305 std::optional<int64_t>
GetIntArg(
const std::string &strArg)
const;
314 bool GetBoolArg(
const std::string &strArg,
bool fDefault)
const;
315 std::optional<bool>
GetBoolArg(
const std::string &strArg)
const;
324 bool SoftSetArg(
const std::string &strArg,
const std::string &strValue);
337 void ForceSetArg(
const std::string &strArg,
const std::string &strValue);
341 const std::vector<std::string> &values);
379 m_available_args.clear();
380 m_network_only_args.clear();
392 std::optional<unsigned int>
GetArgFlags(
const std::string &
name)
const;
399 bool backup =
false)
const;
411 bool backup =
false)
const;
449 std::variant<ChainType, std::string>
GetChainArg()
const;
454 const std::map<std::string, std::vector<util::SettingsValue>>
484 const std::string &message);
488class WinCmdLineArgs {
492 std::pair<int, char **> get();
497 std::vector<std::string> args;
bool HelpRequested(const ArgsManager &args)
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
const char *const BITCOIN_SETTINGS_FILENAME
bool SettingToBool(const util::SettingsValue &, bool)
bool CheckDataDirOption(const ArgsManager &args)
int64_t SettingToInt(const util::SettingsValue &, int64_t)
fs::path AbsPathForConfigVal(const ArgsManager &args, const fs::path &path, bool net_specific=true)
Most paths passed as configuration arguments are treated as relative to the datadir if they are not a...
std::optional< util::SettingsValue > InterpretValue(const KeyInfo &key, const std::optional< std::string > &value, unsigned int flags, std::string &error)
Interpret settings value based on registered flags.
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
KeyInfo InterpretKey(std::string key)
Parse "name", "section.name", "noname", "section.noname" settings keys.
bool ParseKeyValue(std::string &key, std::optional< std::string > &val)
const char *const BITCOIN_CONF_FILENAME
bool IsSwitchChar(char c)
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 &)
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...
bool IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
std::map< OptionsCategory, std::map< std::string, Arg > > m_available_args GUARDED_BY(cs_args)
std::list< SectionInfo > GetUnrecognizedSections() const
Log warnings for unrecognized section names in the config file.
Flags
Flags controlling how config and command line arguments are validated and interpreted.
@ ALLOW_ANY
disable validation
@ DISALLOW_NEGATION
unimplemented, draft implementation in #16545
@ DISALLOW_ELISION
disallow -foo syntax that doesn't assign any value
bool ReadSettingsFile(std::vector< std::string > *errors=nullptr)
Read settings file.
ChainType GetChainType() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
fs::path m_cached_datadir_path GUARDED_BY(cs_args)
std::string GetChainTypeString() const
Returns the appropriate chain name string from the program arguments.
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...
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
std::optional< unsigned int > GetArgFlags(const std::string &name) const
Return Flags for known arg.
std::list< SectionInfo > m_config_sections GUARDED_BY(cs_args)
std::string m_network GUARDED_BY(cs_args)
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.
void LockSettings(Fn &&fn)
Access settings with lock held.
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.
fs::path m_cached_blocks_path GUARDED_BY(cs_args)
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
std::set< std::string > m_network_only_args GUARDED_BY(cs_args)
bool WriteSettingsFile(std::vector< std::string > *errors=nullptr, bool backup=false) const
Write settings file or backup settings file.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
void ClearArgs()
Clear available arguments.
fs::path GetDataDirBase() const
Get data directory path.
fs::path GetBlocksDirPath() const
Get blocks 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)
util::Settings m_settings GUARDED_BY(cs_args)
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.
std::variant< ChainType, std::string > GetChainArg() const
Return -regtest/–testnet/-chain= setting as a ChainType enum if a recognized chain name was set,...
void LogArgs() const
Log the config file options and the command line arguments, useful for troubleshooting.
fs::path GetDataDir(bool net_specific) const
Get data directory path.
fs::path m_cached_network_datadir_path GUARDED_BY(cs_args)
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 ReadConfigStream(std::istream &stream, const std::string &filepath, std::string &error, bool ignore_invalid_keys=false)
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
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.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
bool error(const char *fmt, const Args &...args)
#define EXCLUSIVE_LOCKS_REQUIRED(...)