#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) { cout << "newcoin [options] " << endl; cout << desc << endl; cout << "Commands: " << endl; cout << " account_domain_set []" << endl; cout << " account_email_set []" << endl; cout << " account_info |" << endl; cout << " account_info || []" << endl; cout << " account_message_set " << endl; cout << " account_publish_set " << endl; cout << " account_rate_set " << endl; cout << " account_wallet_set []" << endl; cout << " connect []" << endl; cout << " data_delete " << endl; cout << " data_fetch " << endl; cout << " data_store " << endl; cout << " ledger [|current|lastclosed] [full]" << endl; cout << " logrotate " << endl; cout << " nickname_info " << endl; cout << " nickname_set [] []" << endl; cout << " offer_create [passive]" << endl; cout << " offer_cancel " << endl; cout << " password_fund []" << endl; cout << " password_set []" << endl; cout << " peers" << endl; cout << " ripple ..." << endl; cout << " ripple_lines_get || []" << endl; cout << " ripple_line_set [] []" << endl; cout << " send [] [] []" << endl; cout << " stop" << endl; cout << " tx " << endl; cout << " unl_add | []" << endl; cout << " unl_delete |" << endl; cout << " unl_list" << endl; cout << " unl_load" << endl; cout << " unl_network" << endl; cout << " unl_reset" << endl; cout << " validation_create [||]" << endl; cout << " validation_seed [||]" << endl; cout << " wallet_add [] []" << endl; cout << " wallet_accounts " << endl; cout << " wallet_claim [] []" << endl; cout << " wallet_seed [||]" << endl; cout << " wallet_propose []" << endl; } int main(int argc, char* argv[]) { int iResult = 0; po::variables_map vm; // Map of options. bool bTest = false; // // Set up option parsing. // po::options_description desc("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.") ("verbose,v", "Increase log level.") ; // 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 if (argc >= 2 && !strcmp(argv[1], "--test")) { bTest = true; Log::setMinSeverity(lsTRACE); } else { // Parse options, if no error. try { po::store(po::command_line_parser(argc, argv) .options(desc) // Parse options. .positional(p) // Remainder as --parameters. .run(), vm); po::notify(vm); // Invoke option notify functions. } catch (...) { iResult = 1; } } if (vm.count("verbose")) { Log::setMinSeverity(lsTRACE); } if (!iResult) { theConfig.setup(vm.count("conf") ? vm["conf"].as() : ""); if (vm.count("standalone")) { theConfig.RUN_STANDALONE = true; } } if (iResult) { nothing(); } else if (vm.count("help")) { iResult = 1; } else if (vm.count("test")) { std::cerr << "--test must be first parameter." << std::endl; iResult = 1; } else if (bTest) { iResult = unit_test_main(init_unit_test, argc, argv); } 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) printHelp(desc); return iResult; } // vim:ts=4