|
1 | 1 | /* |
2 | 2 | This file is part of cpp-ethereum. |
| 3 | +
|
3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify |
4 | 5 | it under the terms of the GNU General Public License as published by |
5 | 6 | the Free Software Foundation, either version 3 of the License, or |
|
8 | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | 11 | GNU General Public License for more details. |
| 12 | +
|
11 | 13 | You should have received a copy of the GNU General Public License |
12 | 14 | along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. |
13 | 15 | */ |
@@ -69,33 +71,43 @@ int main(int argc, char** argv) |
69 | 71 | g_logVerbosity = 0; |
70 | 72 | po::options_description generalOptions("General Options"); |
71 | 73 | generalOptions.add_options() |
72 | | - ("verbosity,v", po::value<int>(), "<0 - 9> Set the log verbosity from 0 to 9 (default: 8).") |
73 | | - ("version,V", "Show the version and exit.") |
74 | | - ("help,h", "Show this help message and exit."); |
75 | | - po::parsed_options parsed = po::command_line_parser(argc, argv).options(generalOptions).allow_unregistered().run(); |
76 | | - vector<string> unrecognisedOptions = collect_unrecognized(parsed.options, po::include_positional); |
| 74 | + ("verbosity,v", po::value<int>(), "<0 - 9> Set the log verbosity from 0 to 9 (default: 8).") |
| 75 | + ("version,V", "Show the version and exit.") |
| 76 | + ("help,h", "Show this help message and exit."); |
| 77 | + |
| 78 | + po::variables_map vm; |
| 79 | + vector<string> unrecognisedOptions; |
| 80 | + try |
| 81 | + { |
| 82 | + po::parsed_options parsed = po::command_line_parser(argc, argv).options(generalOptions).allow_unregistered().run(); |
| 83 | + unrecognisedOptions = collect_unrecognized(parsed.options, po::include_positional); |
| 84 | + po::store(parsed, vm); |
| 85 | + po::notify(vm); |
| 86 | + } |
| 87 | + catch (po::error const& e) |
| 88 | + { |
| 89 | + cerr << e.what(); |
| 90 | + return -1; |
| 91 | + } |
| 92 | + |
77 | 93 | for (size_t i = 0; i < unrecognisedOptions.size(); ++i) |
78 | 94 | { |
79 | 95 | string arg = unrecognisedOptions[i]; |
80 | | - //cout << arg << " "; |
81 | | - if (m.interpretOption(i, unrecognisedOptions)) {} |
82 | | - else |
| 96 | + if (!m.interpretOption(i, unrecognisedOptions)) |
83 | 97 | { |
84 | 98 | cerr << "Invalid argument: " << arg << endl; |
85 | | - exit(-1); |
| 99 | + return -1; |
86 | 100 | } |
87 | 101 | } |
88 | | - po::variables_map vm; |
89 | | - po::store(parsed, vm); |
90 | | - po::notify(vm); |
| 102 | + |
91 | 103 | if (vm.count("help")) |
92 | 104 | { |
93 | 105 | cout |
94 | | - << "Usage ethkey [OPTIONS]" << endl |
95 | | - << "Options:" << endl << endl; |
| 106 | + << "Usage ethkey [OPTIONS]" << endl |
| 107 | + << "Options:" << endl << endl; |
96 | 108 | KeyCLI::streamHelp(cout); |
97 | 109 | cout << generalOptions; |
98 | | - exit(0); |
| 110 | + return 0; |
99 | 111 | } |
100 | 112 | if (vm.count("version")) |
101 | 113 | version(); |
|
0 commit comments