forked from ethereum/aleth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
91 lines (74 loc) · 2.61 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Aleth: Ethereum C++ client, tools and libraries.
// Copyright 2015-2019 Aleth Authors.
// Licensed under the GNU General Public License, Version 3.
#include "KeyAux.h"
#include <libdevcore/FileSystem.h>
#include <libdevcore/LoggingProgramOptions.h>
#include <libethcore/Common.h>
#include <libethcore/KeyManager.h>
#include <aleth/buildinfo.h>
#include <boost/program_options.hpp>
#include <boost/program_options/options_description.hpp>
#include <fstream>
#include <iostream>
#include <thread>
using namespace std;
using namespace dev;
using namespace dev::eth;
namespace po = boost::program_options;
void version()
{
const auto* buildinfo = aleth_get_buildinfo();
cout << "aleth-key " << buildinfo->project_version << "\nBuild: " << buildinfo->system_name << "/"
<< buildinfo->build_type << endl;
exit(AlethErrors::Success);
}
int main(int argc, char** argv)
{
setDefaultOrCLocale();
KeyCLI m(KeyCLI::OperationMode::ListBare);
LoggingOptions loggingOptions;
po::options_description loggingProgramOptions(createLoggingProgramOptions(
po::options_description::m_default_line_length, loggingOptions));
po::options_description generalOptions("General Options");
auto addOption = generalOptions.add_options();
addOption("version,V", "Show the version and exit.");
addOption("help,h", "Show this help message and exit.");
po::options_description allowedOptions("Allowed options");
allowedOptions.add(loggingProgramOptions).add(generalOptions);
po::variables_map vm;
vector<string> unrecognisedOptions;
try
{
po::parsed_options parsed =
po::command_line_parser(argc, argv).options(allowedOptions).allow_unregistered().run();
unrecognisedOptions = collect_unrecognized(parsed.options, po::include_positional);
po::store(parsed, vm);
po::notify(vm);
}
catch (po::error const& e)
{
cerr << e.what();
return AlethErrors::ArgumentProcessingFailure;
}
for (size_t i = 0; i < unrecognisedOptions.size(); ++i)
if (!m.interpretOption(i, unrecognisedOptions))
{
cerr << "Invalid argument: " << unrecognisedOptions[i] << endl;
return AlethErrors::ArgumentProcessingFailure;
}
if (vm.count("help"))
{
cout
<< "Usage aleth-key [OPTIONS]" << endl
<< "Options:" << endl << endl;
KeyCLI::streamHelp(cout);
cout << allowedOptions;
return AlethErrors::Success;
}
if (vm.count("version"))
version();
setupLogging(loggingOptions);
m.execute();
return AlethErrors::Success;
}