5#ifndef BITCOIN_COMMON_ARGS_H
6#define BITCOIN_COMMON_ARGS_H
46 return c ==
'-' || c ==
'/';
81 unsigned int flags, std::string& error);
147 [[nodiscard]]
bool ReadConfigStream(std::istream& stream,
const std::string& filepath, std::string& error,
bool ignore_invalid_keys =
false);
169 std::vector<common::SettingsValue>
GetSettingsList(
const std::string& arg)
const;
179 [[nodiscard]]
bool ParseParameters(
int argc,
const char*
const argv[], std::string& error);
186 [[nodiscard]]
bool ReadConfigFiles(std::string& error,
bool ignore_invalid_keys =
false);
213 std::optional<const Command>
GetCommand()
const;
247 std::vector<std::string>
GetArgs(
const std::string& strArg)
const;
255 bool IsArgSet(
const std::string& strArg)
const;
273 std::string
GetArg(
const std::string& strArg,
const std::string& strDefault)
const;
274 std::optional<std::string>
GetArg(
const std::string& strArg)
const;
295 int64_t
GetIntArg(
const std::string& strArg, int64_t nDefault)
const;
296 std::optional<int64_t>
GetIntArg(
const std::string& strArg)
const;
305 bool GetBoolArg(
const std::string& strArg,
bool fDefault)
const;
306 std::optional<bool>
GetBoolArg(
const std::string& strArg)
const;
315 bool SoftSetArg(
const std::string& strArg,
const std::string& strValue);
328 void ForceSetArg(
const std::string& strArg,
const std::string& strValue);
364 m_available_args.clear();
365 m_network_only_args.clear();
384 std::optional<unsigned int>
GetArgFlags(
const std::string&
name)
const;
401 bool WriteSettingsFile(std::vector<std::string>* errors =
nullptr,
bool backup =
false)
const;
412 template <
typename Fn>
440 std::variant<ChainType, std::string>
GetChainArg()
const;
444 const std::string&
prefix,
445 const std::string& section,
446 const std::map<std::string, std::vector<common::SettingsValue>>&
args)
const;
479std::string
HelpMessageOpt(
const std::string& option,
const std::string& message);
488 std::pair<int, char**> get();
493 std::vector<std::string>
args;
const std::vector< std::string > TEST_OPTIONS_DOC
bool HelpRequested(const ArgsManager &args)
void SetupHelpOptions(ArgsManager &args)
Add help options to the args manager.
std::string SettingToString(const common::SettingsValue &, const std::string &)
bool SettingToBool(const common::SettingsValue &, bool)
std::optional< common::SettingsValue > InterpretValue(const KeyInfo &key, const std::string *value, unsigned int flags, std::string &error)
Interpret settings value based on registered flags.
const char *const BITCOIN_SETTINGS_FILENAME
bool CheckDataDirOption(const ArgsManager &args)
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...
int64_t SettingToInt(const common::SettingsValue &, int64_t)
bool HasTestOption(const ArgsManager &args, const std::string &test_option)
Checks if a particular test option is present in -test command-line arg options.
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.
const char *const BITCOIN_CONF_FILENAME
bool IsSwitchChar(char c)
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
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...
std::optional< const Command > GetCommand() const
Get the command and command args (returns std::nullopt if no command provided)
bool IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
void logArgsPrefix(const std::string &prefix, const std::string §ion, const std::map< std::string, std::vector< common::SettingsValue > > &args) const
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
disallow -nofoo syntax
@ DISALLOW_ELISION
disallow -foo syntax that doesn't assign any value
common::SettingsValue GetSetting(const std::string &arg) const
Get setting value.
bool ReadSettingsFile(std::vector< std::string > *errors=nullptr)
Read settings file.
ChainType GetChainType() const
Returns the appropriate chain type from the program arguments.
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 type 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.
void CheckMultipleCLIArgs() const
Check CLI command args.
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::optional< fs::path > m_config_path GUARDED_BY(cs_args)
void SetConfigFilePath(fs::path)
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 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.
std::vector< std::string > m_command GUARDED_BY(cs_args)
void ClearArgs()
Clear available arguments.
fs::path GetDataDirBase() const
Get data directory path.
fs::path GetBlocksDirPath() const
Get blocks directory path.
common::Settings m_settings GUARDED_BY(cs_args)
fs::path GetConfigFilePath() const
Return config file path (read-only)
std::vector< common::SettingsValue > GetSettingsList(const std::string &arg) const
Get list of setting values.
void AddCommand(const std::string &cmd, const std::string &help)
Add subcommand.
std::variant< ChainType, std::string > GetChainArg() const
Return -regtest/-signet/-testnet/-testnet4/-chain= setting as a ChainType enum if a recognized chain ...
bool m_accept_any_command GUARDED_BY(cs_args)
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)
common::SettingsValue GetPersistentSetting(const std::string &name) const
Get current setting from config file or read/write settings file, ignoring nonpersistent command line...
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.
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:...
std::vector< std::string > args
If command is non-empty: Any args that followed it If command is empty: The unregistered command and ...
std::string command
The command (if one has been registered with AddCommand), or empty.
#define EXCLUSIVE_LOCKS_REQUIRED(...)