![]() |
Bitcoin Core
24.99.0
P2P Digital Currency
|
#include <system.h>
Classes | |
struct | Arg |
struct | Command |
Public Types | |
enum | Flags : uint32_t { ALLOW_ANY = 0x01 , DISALLOW_NEGATION = 0x20 , DISALLOW_ELISION = 0x40 , DEBUG_ONLY = 0x100 , NETWORK_ONLY = 0x200 , SENSITIVE = 0x400 , COMMAND = 0x800 } |
Flags controlling how config and command line arguments are validated and interpreted. More... | |
Public Member Functions | |
util::SettingsValue | GetSetting (const std::string &arg) const |
Get setting value. More... | |
std::vector< util::SettingsValue > | GetSettingsList (const std::string &arg) const |
Get list of setting values. More... | |
ArgsManager () | |
~ArgsManager () | |
void | SelectConfigNetwork (const std::string &network) |
Select the network in use. More... | |
bool | ParseParameters (int argc, const char *const argv[], std::string &error) |
fs::path | GetConfigFilePath () const |
Return config file path (read-only) More... | |
bool | ReadConfigFiles (std::string &error, bool ignore_invalid_keys=false) |
std::set< std::string > | GetUnsuitableSectionOnlyArgs () const |
Log warnings for options in m_section_only_args when they are specified in the default section but not overridden on the command line or in a network-specific section in the config file. More... | |
std::list< SectionInfo > | GetUnrecognizedSections () const |
Log warnings for unrecognized section names in the config file. More... | |
std::optional< const Command > | GetCommand () const |
Get the command and command args (returns std::nullopt if no command provided) More... | |
const fs::path & | GetBlocksDirPath () const |
Get blocks directory path. More... | |
const fs::path & | GetDataDirBase () const |
Get data directory path. More... | |
const fs::path & | GetDataDirNet () const |
Get data directory path with appended network identifier. More... | |
void | ClearPathCache () |
Clear cached directory paths. More... | |
std::vector< std::string > | GetArgs (const std::string &strArg) const |
Return a vector of strings of the given argument. More... | |
bool | IsArgSet (const std::string &strArg) const |
Return true if the given argument has been manually set. More... | |
bool | IsArgNegated (const std::string &strArg) const |
Return true if the argument was originally passed as a negated option, i.e. More... | |
std::string | GetArg (const std::string &strArg, const std::string &strDefault) const |
Return string argument or default value. More... | |
std::optional< std::string > | GetArg (const std::string &strArg) const |
fs::path | GetPathArg (std::string arg, const fs::path &default_value={}) const |
Return path argument or default value. More... | |
int64_t | GetIntArg (const std::string &strArg, int64_t nDefault) const |
Return integer argument or default value. More... | |
std::optional< int64_t > | GetIntArg (const std::string &strArg) const |
bool | GetBoolArg (const std::string &strArg, bool fDefault) const |
Return boolean argument or default value. More... | |
std::optional< bool > | GetBoolArg (const std::string &strArg) const |
bool | SoftSetArg (const std::string &strArg, const std::string &strValue) |
Set an argument if it doesn't already have a value. More... | |
bool | SoftSetBoolArg (const std::string &strArg, bool fValue) |
Set a boolean argument if it doesn't already have a value. More... | |
void | ForceSetArg (const std::string &strArg, const std::string &strValue) |
std::string | GetChainName () const |
Returns the appropriate chain name from the program arguments. More... | |
void | AddArg (const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat) |
Add argument. More... | |
void | AddCommand (const std::string &cmd, const std::string &help) |
Add subcommand. More... | |
void | AddHiddenArgs (const std::vector< std::string > &args) |
Add many hidden arguments. More... | |
void | ClearArgs () |
Clear available arguments. More... | |
std::string | GetHelpMessage () const |
Get the help string. More... | |
std::optional< unsigned int > | GetArgFlags (const std::string &name) const |
Return Flags for known arg. More... | |
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. More... | |
bool | ReadSettingsFile (std::vector< std::string > *errors=nullptr) |
Read settings file. More... | |
bool | WriteSettingsFile (std::vector< std::string > *errors=nullptr, bool backup=false) const |
Write settings file or backup settings file. More... | |
util::SettingsValue | GetPersistentSetting (const std::string &name) const |
Get current setting from config file or read/write settings file, ignoring nonpersistent command line or forced settings values. More... | |
template<typename Fn > | |
void | LockSettings (Fn &&fn) |
Access settings with lock held. More... | |
void | LogArgs () const |
Log the config file options and the command line arguments, useful for troubleshooting. More... | |
Protected Member Functions | |
util::Settings m_settings | GUARDED_BY (cs_args) |
std::vector< std::string > m_command | GUARDED_BY (cs_args) |
std::string m_network | GUARDED_BY (cs_args) |
std::set< std::string > m_network_only_args | GUARDED_BY (cs_args) |
std::map< OptionsCategory, std::map< std::string, Arg > > m_available_args | GUARDED_BY (cs_args) |
bool m_accept_any_command | GUARDED_BY (cs_args) |
std::list< SectionInfo > m_config_sections | GUARDED_BY (cs_args) |
fs::path m_cached_blocks_path | GUARDED_BY (cs_args) |
fs::path m_cached_datadir_path | GUARDED_BY (cs_args) |
fs::path m_cached_network_datadir_path | GUARDED_BY (cs_args) |
bool | ReadConfigStream (std::istream &stream, const std::string &filepath, std::string &error, bool ignore_invalid_keys=false) |
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 network and whether the setting is network-specific. More... | |
Protected Attributes | |
RecursiveMutex | cs_args |
Private Member Functions | |
const fs::path & | GetDataDir (bool net_specific) const |
Get data directory path. More... | |
void | logArgsPrefix (const std::string &prefix, const std::string §ion, const std::map< std::string, std::vector< util::SettingsValue >> &args) const |
enum ArgsManager::Flags : uint32_t |
|
default |
|
default |
void ArgsManager::AddArg | ( | const std::string & | name, |
const std::string & | help, | ||
unsigned int | flags, | ||
const OptionsCategory & | cat | ||
) |
Add argument.
Definition at line 672 of file system.cpp.
void ArgsManager::AddCommand | ( | const std::string & | cmd, |
const std::string & | help | ||
) |
Add subcommand.
Definition at line 660 of file system.cpp.
void ArgsManager::AddHiddenArgs | ( | const std::vector< std::string > & | args | ) |
Add many hidden arguments.
Definition at line 693 of file system.cpp.
|
inline |
void ArgsManager::ClearPathCache | ( | ) |
Clear cached directory paths.
Definition at line 441 of file system.cpp.
void ArgsManager::ForceSetArg | ( | const std::string & | strArg, |
const std::string & | strValue | ||
) |
Definition at line 654 of file system.cpp.
std::optional< std::string > ArgsManager::GetArg | ( | const std::string & | strArg | ) | const |
std::string ArgsManager::GetArg | ( | const std::string & | strArg, |
const std::string & | strDefault | ||
) | const |
Return string argument or default value.
strArg | Argument to get (e.g. "-foo") |
strDefault | (e.g. "1") |
Definition at line 565 of file system.cpp.
std::optional< unsigned int > ArgsManager::GetArgFlags | ( | const std::string & | name | ) | const |
Return Flags for known arg.
Return nullopt for unknown arg.
Definition at line 368 of file system.cpp.
std::vector< std::string > ArgsManager::GetArgs | ( | const std::string & | strArg | ) | const |
Return a vector of strings of the given argument.
strArg | Argument to get (e.g. "-foo") |
Definition at line 470 of file system.cpp.
const fs::path & ArgsManager::GetBlocksDirPath | ( | ) | const |
Get blocks directory path.
Definition at line 390 of file system.cpp.
std::optional< bool > ArgsManager::GetBoolArg | ( | const std::string & | strArg | ) | const |
bool ArgsManager::GetBoolArg | ( | const std::string & | strArg, |
bool | fDefault | ||
) | const |
Return boolean argument or default value.
strArg | Argument to get (e.g. "-foo") |
fDefault | (true or false) |
Definition at line 615 of file system.cpp.
std::string ArgsManager::GetChainName | ( | ) | const |
Returns the appropriate chain name from the program arguments.
Definition at line 1016 of file system.cpp.
std::optional< const ArgsManager::Command > ArgsManager::GetCommand | ( | ) | const |
Get the command and command args (returns std::nullopt if no command provided)
Definition at line 450 of file system.cpp.
fs::path ArgsManager::GetConfigFilePath | ( | ) | const |
Return config file path (read-only)
Definition at line 919 of file system.cpp.
|
private |
Get data directory path.
net_specific | Append network identifier to the returned path |
Definition at line 415 of file system.cpp.
|
inline |
|
inline |
std::string ArgsManager::GetHelpMessage | ( | ) | const |
Get the help string.
Definition at line 700 of file system.cpp.
std::optional< int64_t > ArgsManager::GetIntArg | ( | const std::string & | strArg | ) | const |
int64_t ArgsManager::GetIntArg | ( | const std::string & | strArg, |
int64_t | nDefault | ||
) | const |
Return integer argument or default value.
strArg | Argument to get (e.g. "-foo") |
nDefault | (e.g. 1) |
Definition at line 590 of file system.cpp.
Return path argument or default value.
arg | Argument to get a path from (e.g., "-datadir", "-blocksdir" or "-walletdir") |
default_value | Optional default value to return instead of the empty path. |
Definition at line 380 of file system.cpp.
util::SettingsValue ArgsManager::GetPersistentSetting | ( | const std::string & | name | ) | const |
Get current setting from config file or read/write settings file, ignoring nonpersistent command line or forced settings values.
Definition at line 553 of file system.cpp.
util::SettingsValue ArgsManager::GetSetting | ( | const std::string & | arg | ) | const |
Get setting value.
Result will be null if setting was unset, true if "-setting" argument was passed false if "-nosetting" argument was passed, and a string if a "-setting=value" argument was passed.
Definition at line 1051 of file system.cpp.
std::vector< util::SettingsValue > ArgsManager::GetSettingsList | ( | const std::string & | arg | ) | const |
Get list of setting values.
Definition at line 1059 of file system.cpp.
bool ArgsManager::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.
Definition at line 484 of file system.cpp.
std::list< SectionInfo > ArgsManager::GetUnrecognizedSections | ( | ) | const |
Log warnings for unrecognized section names in the config file.
Definition at line 265 of file system.cpp.
std::set< std::string > ArgsManager::GetUnsuitableSectionOnlyArgs | ( | ) | const |
Log warnings for options in m_section_only_args when they are specified in the default section but not overridden on the command line or in a network-specific section in the config file.
Definition at line 245 of file system.cpp.
|
protected |
|
protected |
|
protected |
|
protected |
|
inlineprotected |
|
protected |
bool ArgsManager::IsArgNegated | ( | const std::string & | strArg | ) | const |
Return true if the argument was originally passed as a negated option, i.e.
-nofoo.
strArg | Argument to get (e.g. "-foo") |
Definition at line 560 of file system.cpp.
bool ArgsManager::IsArgSet | ( | const std::string & | strArg | ) | const |
Return true if the given argument has been manually set.
strArg | Argument to get (e.g. "-foo") |
Definition at line 479 of file system.cpp.
|
inline |
void ArgsManager::LogArgs | ( | ) | const |
Log the config file options and the command line arguments, useful for troubleshooting.
Definition at line 1082 of file system.cpp.
|
private |
Definition at line 1065 of file system.cpp.
bool ArgsManager::ParseParameters | ( | int | argc, |
const char *const | argv[], | ||
std::string & | error | ||
) |
Definition at line 287 of file system.cpp.
bool ArgsManager::ReadConfigFiles | ( | std::string & | error, |
bool | ignore_invalid_keys = false |
||
) |
Definition at line 924 of file system.cpp.
|
protected |
Definition at line 890 of file system.cpp.
bool ArgsManager::ReadSettingsFile | ( | std::vector< std::string > * | errors = nullptr | ) |
Read settings file.
Push errors to vector, or log them if null.
Definition at line 510 of file system.cpp.
void ArgsManager::SelectConfigNetwork | ( | const std::string & | network | ) |
Select the network in use.
Definition at line 281 of file system.cpp.
bool ArgsManager::SoftSetArg | ( | const std::string & | strArg, |
const std::string & | strValue | ||
) |
Set an argument if it doesn't already have a value.
strArg | Argument to set (e.g. "-foo") |
strValue | Value (e.g. "1") |
Definition at line 638 of file system.cpp.
bool ArgsManager::SoftSetBoolArg | ( | const std::string & | strArg, |
bool | fValue | ||
) |
Set a boolean argument if it doesn't already have a value.
strArg | Argument to set (e.g. "-foo") |
fValue | Value (e.g. false) |
Definition at line 646 of file system.cpp.
|
protected |
Returns true if settings values from the default section should be used, depending on the current network and whether the setting is network-specific.
Definition at line 1046 of file system.cpp.
bool ArgsManager::WriteSettingsFile | ( | std::vector< std::string > * | errors = nullptr , |
bool | backup = false |
||
) | const |
Write settings file or backup settings file.
Push errors to vector, or log them if null.
Definition at line 533 of file system.cpp.
|
mutableprotected |