Bitcoin ABC 0.32.11
P2P Digital Currency
Namespaces | Functions | Variables
args.cpp File Reference
#include <common/args.h>
#include <chainparamsbase.h>
#include <logging.h>
#include <sync.h>
#include <tinyformat.h>
#include <univalue.h>
#include <util/chaintype.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 <map>
#include <optional>
#include <stdexcept>
#include <string>
#include <variant>
Include dependency graph for args.cpp:

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. More...
 
static std::string SettingName (const std::string &arg)
 
KeyInfo InterpretKey (std::string key)
 Parse "name", "section.name", "noname", "section.noname" settings keys. More...
 
std::optional< util::SettingsValueInterpretValue (const KeyInfo &key, const std::optional< std::string > &value, unsigned int flags, std::string &error)
 Interpret settings value based on registered flags. More...
 
bool ParseKeyValue (std::string &key, std::optional< 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. More...
 
std::string HelpMessageGroup (const std::string &message)
 Format a string to be used as group of options in help messages. More...
 
std::string HelpMessageOpt (const std::string &option, const std::string &message)
 Format a string to be used as option description in help messages. More...
 
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
 

Function Documentation

◆ CheckDataDirOption()

bool CheckDataDirOption ( const ArgsManager args)

Definition at line 752 of file args.cpp.

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

◆ GetDefaultDataDir()

fs::path GetDefaultDataDir ( )

Definition at line 727 of file args.cpp.

Here is the caller graph for this function:

◆ HelpMessageGroup()

std::string HelpMessageGroup ( const std::string &  message)

Format a string to be used as group of options in help messages.

Parameters
messageGroup name (e.g. "RPC server options:")
Returns
the formatted string

Definition at line 715 of file args.cpp.

Here is the caller graph for this function:

◆ HelpMessageOpt()

std::string HelpMessageOpt ( const std::string &  option,
const std::string &  message 
)

Format a string to be used as option description in help messages.

Parameters
optionOption message (e.g. "-rpcuser=<user>")
messageOption description (e.g. "Username for JSON-RPC connections")
Returns
the formatted string

Definition at line 719 of file args.cpp.

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

◆ HelpRequested()

bool HelpRequested ( const ArgsManager args)
Returns
true if help has been requested via a command-line arg

Definition at line 700 of file args.cpp.

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

◆ InterpretBool()

static bool InterpretBool ( const std::string &  strValue)
static

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 58 of file args.cpp.

Here is the caller graph for this function:

◆ InterpretKey()

KeyInfo InterpretKey ( std::string  key)

Parse "name", "section.name", "noname", "section.noname" settings keys.

Note
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 77 of file args.cpp.

Here is the caller graph for this function:

◆ InterpretValue()

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.

Parameters
[in]keykey information to know if key was negated
[in]valuestring value of setting to be parsed
[in]flagsArgsManager registered argument flags
[out]errorError description if settings value is not valid
Returns
parsed settings value if it is valid, otherwise nullopt accompanied by a descriptive error string

Definition at line 106 of file args.cpp.

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

◆ ParseKeyValue()

bool ParseKeyValue ( std::string &  key,
std::optional< std::string > &  val 
)

Definition at line 186 of file args.cpp.

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

◆ SaveErrors()

static void SaveErrors ( const std::vector< std::string >  errors,
std::vector< std::string > *  error_out 
)
static

Definition at line 391 of file args.cpp.

Here is the caller graph for this function:

◆ SettingName()

static std::string SettingName ( const std::string &  arg)
static

Definition at line 65 of file args.cpp.

Here is the caller graph for this function:

◆ SettingToBool() [1/2]

std::optional< bool > SettingToBool ( const util::SettingsValue value)

Definition at line 533 of file args.cpp.

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

◆ SettingToBool() [2/2]

bool SettingToBool ( const util::SettingsValue value,
bool  fDefault 
)

Definition at line 543 of file args.cpp.

Here is the call graph for this function:

◆ SettingToInt() [1/2]

std::optional< int64_t > SettingToInt ( const util::SettingsValue value)

Definition at line 504 of file args.cpp.

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

◆ SettingToInt() [2/2]

int64_t SettingToInt ( const util::SettingsValue value,
int64_t  nDefault 
)

Definition at line 520 of file args.cpp.

Here is the call graph for this function:

◆ SettingToString() [1/2]

std::optional< std::string > SettingToString ( const util::SettingsValue value)

Definition at line 473 of file args.cpp.

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

◆ SettingToString() [2/2]

std::string SettingToString ( const util::SettingsValue value,
const std::string &  strDefault 
)

Definition at line 489 of file args.cpp.

Here is the call graph for this function:

◆ SetupHelpOptions()

void SetupHelpOptions ( ArgsManager args)

Add help options to the args manager.

Definition at line 705 of file args.cpp.

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

Variable Documentation

◆ BITCOIN_CONF_FILENAME

const char* const BITCOIN_CONF_FILENAME = "bitcoin.conf"

Definition at line 36 of file args.cpp.

◆ BITCOIN_SETTINGS_FILENAME

const char* const BITCOIN_SETTINGS_FILENAME = "settings.json"

Definition at line 37 of file args.cpp.

◆ gArgs

ArgsManager gArgs

Definition at line 39 of file args.cpp.

◆ msgIndent

const int msgIndent = 7
static

Definition at line 713 of file args.cpp.

◆ optIndent

const int optIndent = 2
static

Definition at line 712 of file args.cpp.

◆ screenWidth

const int screenWidth = 79
static

Definition at line 711 of file args.cpp.