@@ -50,15 +50,16 @@ static void SetupWalletToolArgs(ArgsManager& argsman)
50
50
argsman.AddCommand (" createfromdump" , " Create new wallet file from dumped records" );
51
51
}
52
52
53
- static bool WalletAppInit (ArgsManager& args, int argc, char * argv[])
53
+ static std::optional< int > WalletAppInit (ArgsManager& args, int argc, char * argv[])
54
54
{
55
55
SetupWalletToolArgs (args);
56
56
std::string error_message;
57
57
if (!args.ParseParameters (argc, argv, error_message)) {
58
58
tfm::format (std::cerr, " Error parsing command line arguments: %s\n " , error_message);
59
- return false ;
59
+ return EXIT_FAILURE ;
60
60
}
61
- if (argc < 2 || HelpRequested (args) || args.IsArgSet (" -version" )) {
61
+ const bool missing_args{argc < 2 };
62
+ if (missing_args || HelpRequested (args) || args.IsArgSet (" -version" )) {
62
63
std::string strUsage = strprintf (" %s bitcoin-wallet version" , PACKAGE_NAME) + " " + FormatFullVersion () + " \n " ;
63
64
64
65
if (args.IsArgSet (" -version" )) {
@@ -73,20 +74,24 @@ static bool WalletAppInit(ArgsManager& args, int argc, char* argv[])
73
74
strUsage += " \n " + args.GetHelpMessage ();
74
75
}
75
76
tfm::format (std::cout, " %s" , strUsage);
76
- return false ;
77
+ if (missing_args) {
78
+ tfm::format (std::cerr, " Error: too few parameters\n " );
79
+ return EXIT_FAILURE;
80
+ }
81
+ return EXIT_SUCCESS;
77
82
}
78
83
79
84
// check for printtoconsole, allow -debug
80
85
LogInstance ().m_print_to_console = args.GetBoolArg (" -printtoconsole" , args.GetBoolArg (" -debug" , false ));
81
86
82
87
if (!CheckDataDirOption ()) {
83
88
tfm::format (std::cerr, " Error: Specified data directory \" %s\" does not exist.\n " , args.GetArg (" -datadir" , " " ));
84
- return false ;
89
+ return EXIT_FAILURE ;
85
90
}
86
91
// Check for chain settings (Params() calls are only valid after this clause)
87
92
SelectParams (args.GetChainName ());
88
93
89
- return true ;
94
+ return std::nullopt ;
90
95
}
91
96
92
97
MAIN_FUNCTION
@@ -106,7 +111,7 @@ MAIN_FUNCTION
106
111
SetupEnvironment ();
107
112
RandomInit ();
108
113
try {
109
- if (! WalletAppInit (args, argc, argv)) return EXIT_FAILURE ;
114
+ if (const auto maybe_exit{ WalletAppInit (args, argc, argv)} ) return *maybe_exit ;
110
115
} catch (const std::exception & e) {
111
116
PrintExceptionContinue (&e, " WalletAppInit()" );
112
117
return EXIT_FAILURE;
0 commit comments