#include "Application.h" #include "CallRPC.h" #include "Config.h" #include "utils.h" #include #include #include #include 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_email_set []" << endl; cout << " account_info |" << endl; cout << " account_info || []" << endl; cout << " account_lines |" << endl; cout << " account_message_set " << endl; cout << " account_wallet_set []" << endl; cout << " connect []" << endl; cout << " credit_set []" << endl; cout << " data_delete " << endl; cout << " data_fetch " << endl; cout << " data_store " << endl; cout << " ledger [|current|lastclosed] [full]" << endl; cout << " nickname_info " << endl; cout << " nickname_set [] []" << endl; cout << " password_fund []" << endl; cout << " password_set []" << endl; cout << " peers" << endl; cout << " send [] [] []" << endl; cout << " stop" << endl; cout << " transit_set " << endl; cout << " tx " << endl; cout << " unl_add | []" << endl; cout << " unl_delete " << endl; cout << " unl_list" << endl; cout << " unl_reset" << endl; cout << " validation_create [||]" << 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).") ("test,t", "Perform unit tests.") ("parameters", po::value< vector >(), "Specify comma separated parameters.") ; // 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; } 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 (!iResult) { theConfig.setup(vm.count("conf") ? vm["conf"].as() : ""); } 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