Remove gArgs from AppInitUtil

Also fix incorrect {}
pull/826/head
MarcoFalke 3 years ago
parent fa751a47ff
commit fa08bc288f
No known key found for this signature in database
GPG Key ID: CE2B75697E69A548

@ -41,22 +41,22 @@ static void SetupBitcoinUtilArgs(ArgsManager &argsman)
// This function returns either one of EXIT_ codes when it's expected to stop the process or
// CONTINUE_EXECUTION when it's expected to continue further.
static int AppInitUtil(int argc, char* argv[])
static int AppInitUtil(ArgsManager& args, int argc, char* argv[])
{
SetupBitcoinUtilArgs(gArgs);
SetupBitcoinUtilArgs(args);
std::string error;
if (!gArgs.ParseParameters(argc, argv, error)) {
if (!args.ParseParameters(argc, argv, error)) {
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error);
return EXIT_FAILURE;
}
if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
if (HelpRequested(args) || args.IsArgSet("-version")) {
// First part of help message is specific to this utility
std::string strUsage = PACKAGE_NAME " bitcoin-util utility version " + FormatFullVersion() + "\n";
if (!gArgs.IsArgSet("-version")) {
if (!args.IsArgSet("-version")) {
strUsage += "\n"
"Usage: bitcoin-util [options] [commands] Do stuff\n";
strUsage += "\n" + gArgs.GetHelpMessage();
strUsage += "\n" + args.GetHelpMessage();
}
tfm::format(std::cout, "%s", strUsage);
@ -70,7 +70,7 @@ static int AppInitUtil(int argc, char* argv[])
// Check for chain settings (Params() calls are only valid after this clause)
try {
SelectParams(gArgs.GetChainName());
SelectParams(args.GetChainName());
} catch (const std::exception& e) {
tfm::format(std::cerr, "Error: %s\n", e.what());
return EXIT_FAILURE;
@ -151,12 +151,14 @@ __declspec(dllexport) int main(int argc, char* argv[])
int main(int argc, char* argv[])
#endif
{
ArgsManager& args = gArgs;
SetupEnvironment();
try {
int ret = AppInitUtil(argc, argv);
if (ret != CONTINUE_EXECUTION)
int ret = AppInitUtil(args, argc, argv);
if (ret != CONTINUE_EXECUTION) {
return ret;
}
} catch (const std::exception& e) {
PrintExceptionContinue(&e, "AppInitUtil()");
return EXIT_FAILURE;
@ -165,7 +167,7 @@ int main(int argc, char* argv[])
return EXIT_FAILURE;
}
const auto cmd = gArgs.GetCommand();
const auto cmd = args.GetCommand();
if (!cmd) {
tfm::format(std::cerr, "Error: must specify a command\n");
return EXIT_FAILURE;

Loading…
Cancel
Save