#include #include #include #include #include #include "Application.h" #include "CallRPC.h" #include "Config.h" #include "utils.h" #include "Log.h" namespace po = boost::program_options; extern bool AddSystemEntropy(); using namespace std; using namespace boost::unit_test; void startServer() { theApp = new Application(); theApp->run(); // Blocks till we get a stop RPC. } bool init_unit_test() { theApp = new Application(); return true; } void printHelp(const po::options_description& desc) { cerr << SYSTEM_NAME "d [options] " << endl; cerr << desc << endl; cerr << "Commands: " << endl; cerr << " account_domain_set []" << endl; cerr << " account_email_set []" << endl; cerr << " account_lines || []" << endl; cerr << " account_offers || []" << endl; cerr << " account_info |" << endl; cerr << " account_info || []" << endl; cerr << " account_message_set " << endl; cerr << " account_publish_set " << endl; cerr << " account_rate_set " << endl; cerr << " account_wallet_set []" << endl; cerr << " connect []" << endl; cerr << " data_delete " << endl; cerr << " data_fetch " << endl; cerr << " data_store " << endl; cerr << " ledger [|current|lastclosed] [full]" << endl; cerr << " logrotate " << endl; cerr << " nickname_info " << endl; cerr << " nickname_set [] []" << endl; cerr << " offer_create [passive]" << endl; cerr << " offer_cancel " << endl; cerr << " password_fund []" << endl; cerr << " password_set []" << endl; cerr << " peers" << endl; cerr << " random" << endl; cerr << " ripple ..." << endl; cerr << " ripple_line_set [] []" << endl; cerr << " send [] [] []" << endl; cerr << " stop" << endl; cerr << " tx " << endl; cerr << " unl_add | []" << endl; cerr << " unl_delete |" << endl; cerr << " unl_list" << endl; cerr << " unl_load" << endl; cerr << " unl_network" << endl; cerr << " unl_reset" << endl; cerr << " validation_create [||]" << endl; cerr << " validation_seed [||]" << endl; cerr << " wallet_add [] []" << endl; cerr << " wallet_accounts " << endl; cerr << " wallet_claim [] []" << endl; cerr << " wallet_seed [||]" << endl; cerr << " wallet_propose []" << endl; } int main(int argc, char* argv[]) { int iResult = 0; po::variables_map vm; // Map of options. // // Set up option parsing. // po::options_description desc("General Options"); desc.add_options() ("help,h", "Display this message.") ("conf", po::value(), "Specify the configuration file.") ("rpc", "Perform rpc command (default).") ("standalone,a", "Run with no peers.") ("test,t", "Perform unit tests.") ("parameters", po::value< vector >(), "Specify comma separated parameters.") ("quiet,q", "Reduce diagnotics.") ("verbose,v", "Verbose logging.") ("load", "Load the current ledger from the local DB.") ("start", "Start from a fresh Ledger.") ("net", "Get the initial ledger from the network.") ; po::options_description hidden("Hidden Options"); hidden.add_options() ("trace,vvv", "Trace level logging") ("debug,vv", "Debug level logging") ; po::options_description all("All Options"); all.add(desc).add(hidden); // Interpret positional arguments as --parameters. po::positional_options_description p; p.add("parameters", -1); // // Prepare to run // if (!AddSystemEntropy()) { std::cerr << "Unable to add system entropy" << std::endl; iResult = 2; } if (iResult) { nothing(); } else { // Parse options, if no error. try { po::store(po::command_line_parser(argc, argv) .options(all) // Parse options. .positional(p) // Remainder as --parameters. .run(), vm); po::notify(vm); // Invoke option notify functions. } catch (...) { iResult = 1; } } if (vm.count("trace")) Log::setMinSeverity(lsTRACE, true); else if (vm.count("debug")) Log::setMinSeverity(lsDEBUG, true); else if (vm.count("verbose")) Log::setMinSeverity(lsINFO, true); else Log::setMinSeverity(lsWARNING, true); InstanceType::multiThread(); if (vm.count("test")) { unit_test_main(init_unit_test, argc, argv); return 0; } if (!iResult) { theConfig.setup( vm.count("conf") ? vm["conf"].as() : "", // Config file. !!vm.count("quiet")); // Quiet flag. if (vm.count("standalone")) { theConfig.RUN_STANDALONE = true; } } if (vm.count("start")) theConfig.START_UP = Config::FRESH; else if (vm.count("load")) theConfig.START_UP = Config::LOAD; else if (vm.count("net")) theConfig.START_UP = Config::NETWORK; if (iResult) { nothing(); } else if (vm.count("help")) { iResult = 1; } else if (!vm.count("parameters")) { // No arguments. Run server. startServer(); } else { // Have a RPC command. std::vector vCmd = vm["parameters"].as >(); iResult = commandLineRPC(vCmd); } if (1 == iResult && !vm.count("quiet")) printHelp(desc); return iResult; } // vim:ts=4