mirror of
https://github.com/monero-project/monero.git
synced 2024-11-18 00:37:43 +00:00
add a command_line function to check for defaulted options
This commit is contained in:
parent
a2041c9874
commit
8f0cea6355
5 changed files with 17 additions and 11 deletions
|
@ -109,7 +109,7 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
mlog_configure(mlog_get_default_log_path("monero-blockchain-export.log"), true);
|
mlog_configure(mlog_get_default_log_path("monero-blockchain-export.log"), true);
|
||||||
if (!vm["log-level"].defaulted())
|
if (!command_line::is_arg_defaulted(vm, arg_log_level))
|
||||||
mlog_set_log(command_line::get_arg(vm, arg_log_level).c_str());
|
mlog_set_log(command_line::get_arg(vm, arg_log_level).c_str());
|
||||||
else
|
else
|
||||||
mlog_set_log(std::string(std::to_string(log_level) + ",bcutil:INFO").c_str());
|
mlog_set_log(std::string(std::to_string(log_level) + ",bcutil:INFO").c_str());
|
||||||
|
|
|
@ -634,7 +634,7 @@ int main(int argc, char* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! opt_batch && ! vm["batch-size"].defaulted())
|
if (! opt_batch && !command_line::is_arg_defaulted(vm, arg_batch_size))
|
||||||
{
|
{
|
||||||
std::cerr << "Error: batch-size set, but batch option not enabled" << ENDL;
|
std::cerr << "Error: batch-size set, but batch option not enabled" << ENDL;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -644,7 +644,7 @@ int main(int argc, char* argv[])
|
||||||
std::cerr << "Error: batch-size must be > 0" << ENDL;
|
std::cerr << "Error: batch-size must be > 0" << ENDL;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (opt_verify && vm["batch-size"].defaulted())
|
if (opt_verify && command_line::is_arg_defaulted(vm, arg_batch_size))
|
||||||
{
|
{
|
||||||
// usually want batch size default lower if verify on, so progress can be
|
// usually want batch size default lower if verify on, so progress can be
|
||||||
// frequently saved.
|
// frequently saved.
|
||||||
|
@ -663,7 +663,7 @@ int main(int argc, char* argv[])
|
||||||
db_arg_str = command_line::get_arg(vm, arg_database);
|
db_arg_str = command_line::get_arg(vm, arg_database);
|
||||||
|
|
||||||
mlog_configure(mlog_get_default_log_path("monero-blockchain-import.log"), true);
|
mlog_configure(mlog_get_default_log_path("monero-blockchain-import.log"), true);
|
||||||
if (!vm["log-level"].defaulted())
|
if (!command_line::is_arg_defaulted(vm, arg_log_level))
|
||||||
mlog_set_log(command_line::get_arg(vm, arg_log_level).c_str());
|
mlog_set_log(command_line::get_arg(vm, arg_log_level).c_str());
|
||||||
else
|
else
|
||||||
mlog_set_log(std::string(std::to_string(log_level) + ",bcutil:INFO").c_str());
|
mlog_set_log(std::string(std::to_string(log_level) + ",bcutil:INFO").c_str());
|
||||||
|
@ -735,7 +735,7 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
core.get_blockchain_storage().get_db().set_batch_transactions(true);
|
core.get_blockchain_storage().get_db().set_batch_transactions(true);
|
||||||
|
|
||||||
if (! vm["pop-blocks"].defaulted())
|
if (!command_line::is_arg_defaulted(vm, arg_pop_blocks))
|
||||||
{
|
{
|
||||||
num_blocks = command_line::get_arg(vm, arg_pop_blocks);
|
num_blocks = command_line::get_arg(vm, arg_pop_blocks);
|
||||||
MINFO("height: " << core.get_blockchain_storage().get_current_blockchain_height());
|
MINFO("height: " << core.get_blockchain_storage().get_current_blockchain_height());
|
||||||
|
@ -744,7 +744,7 @@ int main(int argc, char* argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! vm["drop-hard-fork"].defaulted())
|
if (!command_line::is_arg_defaulted(vm, arg_drop_hf))
|
||||||
{
|
{
|
||||||
MINFO("Dropping hard fork tables...");
|
MINFO("Dropping hard fork tables...");
|
||||||
core.get_blockchain_storage().get_db().drop_hard_fork_info();
|
core.get_blockchain_storage().get_db().drop_hard_fork_info();
|
||||||
|
|
|
@ -189,6 +189,12 @@ namespace command_line
|
||||||
return !value.empty();
|
return !value.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, bool required>
|
||||||
|
bool is_arg_defaulted(const boost::program_options::variables_map& vm, const arg_descriptor<T, required>& arg)
|
||||||
|
{
|
||||||
|
return vm[arg.name].defaulted();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename T, bool required>
|
template<typename T, bool required>
|
||||||
T get_arg(const boost::program_options::variables_map& vm, const arg_descriptor<T, required>& arg)
|
T get_arg(const boost::program_options::variables_map& vm, const arg_descriptor<T, required>& arg)
|
||||||
|
|
|
@ -205,13 +205,13 @@ int main(int argc, char const * argv[])
|
||||||
// absolute path
|
// absolute path
|
||||||
// relative path: relative to data_dir
|
// relative path: relative to data_dir
|
||||||
bf::path log_file_path {data_dir / std::string(CRYPTONOTE_NAME ".log")};
|
bf::path log_file_path {data_dir / std::string(CRYPTONOTE_NAME ".log")};
|
||||||
if (! vm["log-file"].defaulted())
|
if (!command_line::is_arg_defaulted(vm, daemon_args::arg_log_file))
|
||||||
log_file_path = command_line::get_arg(vm, daemon_args::arg_log_file);
|
log_file_path = command_line::get_arg(vm, daemon_args::arg_log_file);
|
||||||
log_file_path = bf::absolute(log_file_path, relative_path_base);
|
log_file_path = bf::absolute(log_file_path, relative_path_base);
|
||||||
mlog_configure(log_file_path.string(), true, command_line::get_arg(vm, daemon_args::arg_max_log_file_size));
|
mlog_configure(log_file_path.string(), true, command_line::get_arg(vm, daemon_args::arg_max_log_file_size));
|
||||||
|
|
||||||
// Set log level
|
// Set log level
|
||||||
if (!vm["log-level"].defaulted())
|
if (!command_line::is_arg_defaulted(vm, daemon_args::arg_log_level))
|
||||||
{
|
{
|
||||||
mlog_set_log(command_line::get_arg(vm, daemon_args::arg_log_level).c_str());
|
mlog_set_log(command_line::get_arg(vm, daemon_args::arg_log_level).c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,12 +154,12 @@ namespace wallet_args
|
||||||
return boost::none;
|
return boost::none;
|
||||||
|
|
||||||
std::string log_path;
|
std::string log_path;
|
||||||
if (!vm["log-file"].defaulted())
|
if (!command_line::is_arg_defaulted(vm, arg_log_file))
|
||||||
log_path = command_line::get_arg(vm, arg_log_file);
|
log_path = command_line::get_arg(vm, arg_log_file);
|
||||||
else
|
else
|
||||||
log_path = mlog_get_default_log_path(default_log_name);
|
log_path = mlog_get_default_log_path(default_log_name);
|
||||||
mlog_configure(log_path, log_to_console, command_line::get_arg(vm, arg_max_log_file_size));
|
mlog_configure(log_path, log_to_console, command_line::get_arg(vm, arg_max_log_file_size));
|
||||||
if (!vm["log-level"].defaulted())
|
if (!command_line::is_arg_defaulted(vm, arg_log_level))
|
||||||
{
|
{
|
||||||
mlog_set_log(command_line::get_arg(vm, arg_log_level).c_str());
|
mlog_set_log(command_line::get_arg(vm, arg_log_level).c_str());
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ namespace wallet_args
|
||||||
|
|
||||||
tools::scoped_message_writer(epee::console_color_white, true) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
|
tools::scoped_message_writer(epee::console_color_white, true) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
|
||||||
|
|
||||||
if (!vm["log-level"].defaulted())
|
if (!command_line::is_arg_defaulted(vm, arg_log_level))
|
||||||
MINFO("Setting log level = " << command_line::get_arg(vm, arg_log_level));
|
MINFO("Setting log level = " << command_line::get_arg(vm, arg_log_level));
|
||||||
else
|
else
|
||||||
MINFO("Setting log levels = " << getenv("MONERO_LOGS"));
|
MINFO("Setting log levels = " << getenv("MONERO_LOGS"));
|
||||||
|
|
Loading…
Reference in a new issue