Bitcoin ABC  0.24.10
P2P Digital Currency
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
ArgsManager Class Reference

#include <system.h>

Collaboration diagram for ArgsManager:
[legend]

Classes

struct  Arg
 

Public Types

enum  Flags {
  ALLOW_BOOL = 0x01, ALLOW_INT = 0x02, ALLOW_STRING = 0x04, ALLOW_ANY = ALLOW_BOOL | ALLOW_INT | ALLOW_STRING,
  DEBUG_ONLY = 0x100, NETWORK_ONLY = 0x200, SENSITIVE = 0x400
}
 

Public Member Functions

 ArgsManager ()
 
 ~ArgsManager ()
 
void SelectConfigNetwork (const std::string &network)
 Select the network in use. More...
 
NODISCARD bool ParseParameters (int argc, const char *const argv[], std::string &error)
 
NODISCARD bool ReadConfigFiles (std::string &error, bool ignore_invalid_keys=false)
 
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 not overridden on the command line or in a network-specific section in the config file. More...
 
const std::list< SectionInfoGetUnrecognizedSections () const
 Log warnings for unrecognized section names in the config file. More...
 
const fs::pathGetBlocksDirPath ()
 Get blocks directory path. More...
 
const fs::pathGetDataDirPath (bool net_specific=true) const
 Get data directory path. 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...
 
int64_t GetArg (const std::string &strArg, int64_t nDefault) const
 Return integer argument or default value. More...
 
bool GetBoolArg (const std::string &strArg, bool fDefault) const
 Return boolean argument or default value. More...
 
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)
 
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 integrity of mapMultiArgs data structure. More...
 
std::string GetChainName () const
 Looks for -regtest, -testnet and returns the appropriate BIP70 chain name. More...
 
void AddArg (const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
 Add argument. More...
 
void ClearForcedArg (const std::string &strArg)
 Remove a forced arg setting, used only in testing. 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 InitSettings (std::string &error)
 Read and update settings file with saved settings. More...
 
bool GetSettingsPath (fs::path *filepath=nullptr, bool temp=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) const
 Write settings file. 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::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)
 
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)
 
NODISCARD 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...
 
util::SettingsValue GetSetting (const std::string &arg) const
 Get setting value. More...
 
std::vector< util::SettingsValueGetSettingsList (const std::string &arg) const
 Get list of setting values. More...
 

Protected Attributes

RecursiveMutex cs_args
 

Private Member Functions

void logArgsPrefix (const std::string &prefix, const std::string &section, const std::map< std::string, std::vector< util::SettingsValue >> &args) const
 

Detailed Description

Definition at line 148 of file system.h.

Member Enumeration Documentation

◆ Flags

Enumerator
ALLOW_BOOL 
ALLOW_INT 
ALLOW_STRING 
ALLOW_ANY 
DEBUG_ONLY 
NETWORK_ONLY 
SENSITIVE 

Definition at line 150 of file system.h.

Constructor & Destructor Documentation

◆ ArgsManager()

ArgsManager::ArgsManager ( )

Definition at line 259 of file system.cpp.

◆ ~ArgsManager()

ArgsManager::~ArgsManager ( )

Definition at line 260 of file system.cpp.

Member Function Documentation

◆ AddArg()

void ArgsManager::AddArg ( const std::string &  name,
const std::string &  help,
unsigned int  flags,
const OptionsCategory cat 
)

Add argument.

Definition at line 649 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddHiddenArgs()

void ArgsManager::AddHiddenArgs ( const std::vector< std::string > &  args)

Add many hidden arguments.

Definition at line 671 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ClearArgs()

void ArgsManager::ClearArgs ( )
inline

Clear available arguments.

Definition at line 367 of file system.h.

◆ ClearForcedArg()

void ArgsManager::ClearForcedArg ( const std::string &  strArg)

Remove a forced arg setting, used only in testing.

Definition at line 677 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ClearPathCache()

void ArgsManager::ClearPathCache ( )

Clear cached directory paths.

Definition at line 465 of file system.cpp.

Here is the caller graph for this function:

◆ ForceSetArg()

void ArgsManager::ForceSetArg ( const std::string &  strArg,
const std::string &  strValue 
)

Definition at line 626 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ForceSetMultiArg()

void ArgsManager::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 integrity of mapMultiArgs data structure.

Definition at line 637 of file system.cpp.

Here is the call graph for this function:

◆ GetArg() [1/2]

std::string ArgsManager::GetArg ( const std::string &  strArg,
const std::string &  strDefault 
) const

Return string argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
strDefault(e.g. "1")
Returns
command-line argument or default value

Definition at line 582 of file system.cpp.

Here is the call graph for this function:

◆ GetArg() [2/2]

int64_t ArgsManager::GetArg ( const std::string &  strArg,
int64_t  nDefault 
) const

Return integer argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
nDefault(e.g. 1)
Returns
command-line argument (0 if invalid number) or default value

Definition at line 590 of file system.cpp.

Here is the call graph for this function:

◆ GetArgFlags()

std::optional< unsigned int > ArgsManager::GetArgFlags ( const std::string &  name) const

Return Flags for known arg.

Return std::nullopt for unknown arg.

Definition at line 393 of file system.cpp.

Here is the caller graph for this function:

◆ GetArgs()

std::vector< std::string > ArgsManager::GetArgs ( const std::string &  strArg) const

Return a vector of strings of the given argument.

Parameters
strArgArgument to get (e.g. "-foo")
Returns
command-line arguments

Definition at line 473 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBlocksDirPath()

const fs::path & ArgsManager::GetBlocksDirPath ( )

Get blocks directory path.

Returns
Blocks path which is network specific

Definition at line 404 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBoolArg()

bool ArgsManager::GetBoolArg ( const std::string &  strArg,
bool  fDefault 
) const

Return boolean argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
fDefault(true or false)
Returns
command-line argument or default value

Definition at line 601 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetChainName()

std::string ArgsManager::GetChainName ( ) const

Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.

Returns
CBaseChainParams::MAIN by default; raises runtime error if an invalid combination is given.

Definition at line 1043 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDataDirPath()

const fs::path & ArgsManager::GetDataDirPath ( bool  net_specific = true) const

Get data directory path.

Parameters
net_specificAppend network identifier to the returned path
Returns
Absolute path on success, otherwise an empty path when a non-directory path would be returned
Postcondition
Returned directory path is created unless it is empty

Definition at line 432 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetHelpMessage()

std::string ArgsManager::GetHelpMessage ( ) const

Get the help string.

Definition at line 682 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSetting()

util::SettingsValue ArgsManager::GetSetting ( const std::string &  arg) const
protected

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 1077 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSettingsList()

std::vector< util::SettingsValue > ArgsManager::GetSettingsList ( const std::string &  arg) const
protected

Get list of setting values.

Definition at line 1085 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSettingsPath()

bool ArgsManager::GetSettingsPath ( fs::path filepath = nullptr,
bool  temp = false 
) const

Get settings file path, or return false if read-write settings were disabled with -nosettings.

Definition at line 505 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetUnrecognizedSections()

const std::list< SectionInfo > ArgsManager::GetUnrecognizedSections ( ) const

Log warnings for unrecognized section names in the config file.

Definition at line 286 of file system.cpp.

Here is the caller graph for this function:

◆ GetUnsuitableSectionOnlyArgs()

const 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 262 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GUARDED_BY() [1/8]

util::Settings m_settings ArgsManager::GUARDED_BY ( cs_args  )
protected

◆ GUARDED_BY() [2/8]

std::string m_network ArgsManager::GUARDED_BY ( cs_args  )
protected

◆ GUARDED_BY() [3/8]

std::set<std::string> m_network_only_args ArgsManager::GUARDED_BY ( cs_args  )
protected

◆ GUARDED_BY() [4/8]

std::map<OptionsCategory, std::map<std::string, Arg> > m_available_args ArgsManager::GUARDED_BY ( cs_args  )
protected

◆ GUARDED_BY() [5/8]

std::list<SectionInfo> m_config_sections ArgsManager::GUARDED_BY ( cs_args  )
protected

◆ GUARDED_BY() [6/8]

fs::path m_cached_blocks_path ArgsManager::GUARDED_BY ( cs_args  )
protected

◆ GUARDED_BY() [7/8]

fs::path m_cached_datadir_path ArgsManager::GUARDED_BY ( cs_args  )
mutableprotected

◆ GUARDED_BY() [8/8]

fs::path m_cached_network_datadir_path ArgsManager::GUARDED_BY ( cs_args  )
mutableprotected

◆ InitSettings()

bool ArgsManager::InitSettings ( std::string &  error)

Read and update settings file with saved settings.

This needs to be called after SelectParams() because the settings file location is network-specific.

Definition at line 486 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsArgNegated()

bool ArgsManager::IsArgNegated ( const std::string &  strArg) const

Return true if the argument was originally passed as a negated option, i.e.

-nofoo.

Parameters
strArgArgument to get (e.g. "-foo")
Returns
true if the argument was passed negated

Definition at line 578 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsArgSet()

bool ArgsManager::IsArgSet ( const std::string &  strArg) const

Return true if the given argument has been manually set.

Parameters
strArgArgument to get (e.g. "-foo")
Returns
true if the argument has been set

Definition at line 482 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LockSettings()

template<typename Fn >
void ArgsManager::LockSettings ( Fn &&  fn)
inline

Access settings with lock held.

Definition at line 410 of file system.h.

Here is the caller graph for this function:

◆ LogArgs()

void ArgsManager::LogArgs ( ) const

Log the config file options and the command line arguments, useful for troubleshooting.

Definition at line 1108 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logArgsPrefix()

void ArgsManager::logArgsPrefix ( const std::string &  prefix,
const std::string &  section,
const std::map< std::string, std::vector< util::SettingsValue >> &  args 
) const
private

Definition at line 1091 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParseParameters()

bool ArgsManager::ParseParameters ( int  argc,
const char *const  argv[],
std::string &  error 
)

Definition at line 330 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadConfigFiles()

bool ArgsManager::ReadConfigFiles ( std::string &  error,
bool  ignore_invalid_keys = false 
)

Definition at line 940 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadConfigStream()

bool ArgsManager::ReadConfigStream ( std::istream &  stream,
const std::string &  filepath,
std::string &  error,
bool  ignore_invalid_keys = false 
)
protected

Definition at line 905 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadSettingsFile()

bool ArgsManager::ReadSettingsFile ( std::vector< std::string > *  errors = nullptr)

Read settings file.

Push errors to vector, or log them if null.

Definition at line 529 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SelectConfigNetwork()

void ArgsManager::SelectConfigNetwork ( const std::string &  network)

Select the network in use.

Definition at line 301 of file system.cpp.

Here is the caller graph for this function:

◆ SoftSetArg()

bool ArgsManager::SoftSetArg ( const std::string &  strArg,
const std::string &  strValue 
)

Set an argument if it doesn't already have a value.

Parameters
strArgArgument to set (e.g. "-foo")
strValueValue (e.g. "1")
Returns
true if argument gets set, false if it already had a value

Definition at line 608 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SoftSetBoolArg()

bool ArgsManager::SoftSetBoolArg ( const std::string &  strArg,
bool  fValue 
)

Set a boolean argument if it doesn't already have a value.

Parameters
strArgArgument to set (e.g. "-foo")
fValueValue (e.g. false)
Returns
true if argument gets set, false if it already had a value

Definition at line 618 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UseDefaultSection()

bool ArgsManager::UseDefaultSection ( const std::string &  arg) const
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 1072 of file system.cpp.

Here is the caller graph for this function:

◆ WriteSettingsFile()

bool ArgsManager::WriteSettingsFile ( std::vector< std::string > *  errors = nullptr) const

Write settings file.

Push errors to vector, or log them if null.

Definition at line 554 of file system.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ cs_args

RecursiveMutex ArgsManager::cs_args
mutableprotected

Definition at line 174 of file system.h.


The documentation for this class was generated from the following files: