From d255eb960b4191eff8e9650c32e0b3db6e136e59 Mon Sep 17 00:00:00 2001 From: Alexandra Drozdova Date: Fri, 8 Dec 2017 16:31:41 +0100 Subject: [PATCH 1/8] Use boost.program_options to handle command line arguments in eth and ethkey --- eth/CMakeLists.txt | 2 +- eth/MinerAux.h | 3 +- eth/main.cpp | 978 +++++++++++++++++++++++------------------- ethkey/CMakeLists.txt | 2 +- ethkey/KeyAux.h | 3 +- ethkey/main.cpp | 60 +-- 6 files changed, 564 insertions(+), 484 deletions(-) diff --git a/eth/CMakeLists.txt b/eth/CMakeLists.txt index 8de0dc2b0e0..584dd27445d 100644 --- a/eth/CMakeLists.txt +++ b/eth/CMakeLists.txt @@ -8,7 +8,7 @@ set( add_executable(eth ${sources}) target_link_libraries( eth - PRIVATE ethereum ethashseal evm web3jsonrpc webthree devcore + PRIVATE ethereum ethashseal evm web3jsonrpc webthree devcore Boost::program_options ) target_include_directories(eth PRIVATE ../utils) diff --git a/eth/MinerAux.h b/eth/MinerAux.h index d0d72abcd46..f75564a895d 100644 --- a/eth/MinerAux.h +++ b/eth/MinerAux.h @@ -101,8 +101,9 @@ class MinerCLI BasicAuthority::init(); } - bool interpretOption(int& i, int argc, char** argv) + bool interpretOption(size_t& i, vector const& argv) { + size_t argc = argv.size(); string arg = argv[i]; if (arg == "--benchmark-warmup" && i + 1 < argc) try { diff --git a/eth/main.cpp b/eth/main.cpp index 520022475ea..8910963ff88 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -1,16 +1,13 @@ /* This file is part of cpp-ethereum. - cpp-ethereum is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ @@ -30,6 +27,8 @@ #include #include #include +#include +#include #include #include @@ -66,100 +65,16 @@ using namespace dev; using namespace dev::p2p; using namespace dev::eth; using namespace boost::algorithm; +namespace po = boost::program_options; namespace fs = boost::filesystem; static std::atomic g_silence = {false}; -void help() -{ - cout - << "Usage eth [OPTIONS]\n" - << "Options:\n\n" - << "Wallet usage:\n"; - AccountManager::streamAccountHelp(cout); - AccountManager::streamWalletHelp(cout); - cout - << "\nClient mode (default):\n" - << " --mainnet Use the main network protocol.\n" - << " --ropsten Use the Ropsten testnet.\n" - << " --private Use a private chain.\n" - << " --test Testing mode: Disable PoW and provide test rpc interface.\n" - << " --config Configure specialised blockchain using given JSON information.\n" - << " -o,--mode Start a full node or a peer node (default: full).\n\n" - << " --ipc Enable IPC server (default: on).\n" - << " --ipcpath Set .ipc socket path (default: data directory)\n" - << " --no-ipc Disable IPC server.\n" - << " --admin Specify admin session key for JSON-RPC (default: auto-generated and printed at start-up).\n" - << " -K,--kill Kill the blockchain first.\n" - << " -R,--rebuild Rebuild the blockchain from the existing database.\n" - << " --rescue Attempt to rescue a corrupt database.\n\n" - << " --import-presale Import a pre-sale key; you'll need to specify the password to this key.\n" - << " -s,--import-secret Import a secret key into the key store.\n" - << " --master Give the master password for the key store. Use --master \"\" to show a prompt.\n" - << " --password Give a password for a private key.\n\n" - << "Client transacting:\n" - << " --ask Set the minimum ask gas price under which no transaction will be mined (default " << toString(DefaultGasPrice) << " ).\n" - << " --bid Set the bid gas price to pay for transactions (default " << toString(DefaultGasPrice) << " ).\n" - << " --unsafe-transactions Allow all transactions to proceed without verification. EXTREMELY UNSAFE.\n" - << "Client mining:\n" - << " -a,--address Set the author (mining payout) address to given address (default: auto).\n" - << " -m,--mining Enable mining, optionally for a specified number of blocks (default: off).\n" - << " -f,--force-mining Mine even when there are no transactions to mine (default: off).\n" - << " -C,--cpu When mining, use the CPU.\n" - << " -t, --mining-threads Limit number of CPU/GPU miners to n (default: use everything available on selected platform).\n\n" - << "Client networking:\n" - << " --client-name Add a name to your client's version string (default: blank).\n" - << " --bootstrap Connect to the default Ethereum peer servers (default unless --no-discovery used).\n" - << " --no-bootstrap Do not connect to the default Ethereum peer servers (default only when --no-discovery is used).\n" - << " -x,--peers Attempt to connect to a given number of peers (default: 11).\n" - << " --peer-stretch Give the accepted connection multiplier (default: 7).\n" - - << " --public-ip Force advertised public IP to the given IP (default: auto).\n" - << " --listen-ip (:) Listen on the given IP for incoming connections (default: 0.0.0.0).\n" - << " --listen Listen on the given port for incoming connections (default: 30303).\n" - << " -r,--remote (:) Connect to the given remote host (default: none).\n" - << " --port Connect to the given remote port (default: 30303).\n" - << " --network-id Only connect to other hosts with this network id.\n" - << " --upnp Use UPnP for NAT (default: on).\n" - - << " --peerset Space delimited list of peers; element format: type:publickey@ipAddress[:port].\n" - << " Types:\n" - << " default Attempt connection when no other peers are available and pinning is disabled.\n" - << " required Keep connected at all times.\n" -// TODO: -// << " --trust-peers Space delimited list of publickeys." << endl - - << " --no-discovery Disable node discovery, implies --no-bootstrap.\n" - << " --pin Only accept or connect to trusted peers.\n" - << " --hermit Equivalent to --no-discovery --pin.\n" - << " --sociable Force discovery and no pinning.\n\n"; - MinerCLI::streamHelp(cout); - cout - << "Import/export modes:\n" - << " --from Export only from block n; n may be a decimal, a '0x' prefixed hash, or 'latest'.\n" - << " --to Export only to block n (inclusive); n may be a decimal, a '0x' prefixed hash, or 'latest'.\n" - << " --only Equivalent to --export-from n --export-to n.\n" - << " --dont-check Prevent checking some block aspects. Faster importing, but to apply only when the data is known to be valid.\n\n" - << " --import-snapshot Import blockchain and state data from the Parity Warp Sync snapshot." << endl - << "General Options:\n" - << " -d,--db-path,--datadir Load database from path (default: " << getDataDir() << ").\n" -#if ETH_EVMJIT - << " --vm Select VM; options are: interpreter, jit or smart (default: interpreter).\n" -#endif // ETH_EVMJIT - << " -v,--verbosity <0 - 9> Set the log verbosity from 0 to 9 (default: 8).\n" - << " -V,--version Show the version and exit.\n" - << " -h,--help Show this help message and exit.\n\n" - << "Experimental / Proof of Concept:\n" - << " --shh Enable Whisper.\n\n"; - exit(0); -} - string ethCredits(bool _interactive = false) { std::ostringstream cout; if (_interactive) - cout - << "Type 'exit' to quit\n\n"; + cout << "Type 'exit' to quit\n\n"; return credits() + cout.str(); } @@ -179,7 +94,6 @@ to set locale to fail, so there are only two possible actions, the first is to throw a runtime exception and cause the program to quit (default behaviour), or the second is to modify the environment to something sensible (least surprising behaviour). - The follow code produces the least surprising behaviour. It will use the user specified default locale if it is valid, and if not then it will modify the environment the process is running in to use a sensible default. This also means @@ -389,395 +303,553 @@ int main(int argc, char** argv) bool chainConfigIsSet = false; string configJSON; string genesisJSON; - for (int i = 1; i < argc; ++i) + po::options_description clientDefaultMode("Client mode (default)"); + clientDefaultMode.add_options() + ("format", po::value(), " Set format.") + ("script", po::value(), "