Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing ethvm/main.cpp and ethkey/main.cpp
  • Loading branch information
demon1999 committed Oct 5, 2017
commit 7ce58ad209fc55b8ff55db9e69e2aaa239eb66f7
2 changes: 1 addition & 1 deletion ethkey/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_executable(ethkey KeyAux.h main.cpp)
target_link_libraries(ethkey PRIVATE ethcore devcore)
target_link_libraries(ethkey PRIVATE ethcore devcore Boost::program_options)
43 changes: 36 additions & 7 deletions ethkey/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@
#include <libdevcore/FileSystem.h>
#include <libdevcore/Log.h>
#include <libethcore/KeyManager.h>
#include <boost/program_options.hpp>
#include <boost/program_options/options_description.hpp>
#include "BuildInfo.h"
#include "KeyAux.h"
using namespace std;
using namespace dev;
using namespace dev::eth;

namespace po = boost::program_options;

void help()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this function?

{
cout
Expand Down Expand Up @@ -82,23 +86,48 @@ int main(int argc, char** argv)
setDefaultOrCLocale();
KeyCLI m(KeyCLI::OperationMode::ListBare);
g_logVerbosity = 0;

po::options_description generalOptions("General Options");
generalOptions.add_options()
("verbosity,v", po::value<string>(), "<0 - 9> Set the log verbosity from 0 to 9 (default: 8).")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we make it po::value<int> ?

("version,V", "Show the version and exit.")
("help,h", "Show this help message and exit.")
;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This formatting looks weird in our style, please leave semicolon on the last line of the statement.

int ac = 1;
for (int i = 1; i < argc; ++i)
{
string arg = argv[i];
if (m.interpretOption(i, argc, argv)) {}
else if ((arg == "-v" || arg == "--verbosity") && i + 1 < argc)
g_logVerbosity = atoi(argv[++i]);
else if (arg == "-h" || arg == "--help")
help();
else if (arg == "-V" || arg == "--version")
version();
else if (((arg == "-v" || arg == "--verbosity") && i + 1 < argc) || arg == "-h" || arg == "--help" || arg == "-V" || arg == "--version") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opening brace should be on a separate line

argv[ac] = argv[i];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain what are you trying to achieve in this part?
I don't think assiging to argv is a very good idea

I think you're trying to get rid of all the options that are handled in KeyCLI::interpretOption() and leave only -v, -V, -h in argv
Why do you need this? Wouldn't po::store(po::parse_command_line(ac, argv, generalOptions), vm); below just ignore options not listed in generalOptions ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ac++;
if (arg == "-v" || arg == "--verbosity") {
i++;
argv[ac] = argv[i];
ac++;
}
continue;
}
else
{
cerr << "Invalid argument: " << arg << endl;
exit(-1);
}
}
po::variables_map vm;
po::store(po::parse_command_line(ac, argv, generalOptions), vm);
po::notify(vm);
if (vm.count("help")) {
cout
<< "Usage ethkey [OPTIONS]" << endl
<< "Options:" << endl << endl;
KeyCLI::streamHelp(cout);
cout << generalOptions;
exit(0);
}
if (vm.count("version"))
version();
if (vm.count("verbosity"))
g_logVerbosity = atoi(vm["verbosity"].as<string>().c_str());

m.execute();

Expand Down
67 changes: 42 additions & 25 deletions ethvm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,47 @@ int main(int argc, char** argv)
po::options_description allowedOptions("Usage ethvm <options> [trace|stats|output|test] (<file>|-)");
allowedOptions.add(vmOptions).add(networkOptions).add(optionsForTrace).add(generalOptions).add(transactionOptions);
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, allowedOptions), vm);
int ac = 1;
for (int i = 1; i < argc; ++i) {
string arg = argv[i];
if ((i + 1 < argc && (arg == "--vm" || arg == "--sender" ||
arg == "--origin" || arg == "--gas" || arg == "--gas-price" || arg == "--author" ||
arg == "--number" ||
arg == "--difficulty" || arg == "--timestamp" || arg == "--gas-limit" ||
arg == "--value" || arg == "--network" ||
arg == "--input" || arg == "--code")) || arg == "--mnemonics" || arg == "--flat" ||
arg == "-h" || arg == "--help" || arg == "--version" || arg == "-V") {
argv[ac] = argv[i];
ac++;
if (arg == "--vm" || arg == "--sender" ||
arg == "--origin" || arg == "--gas" || arg == "--gas-price" || arg == "--author" ||
arg == "--number" ||
arg == "--difficulty" || arg == "--timestamp" || arg == "--gas-limit" ||
arg == "--value" || arg == "--network" ||
arg == "--input" || arg == "--code") {
i++;
argv[ac] = argv[i];
ac++;
}
continue;
}
else if (arg == "stats")
mode = Mode::Statistics;
else if (arg == "output")
mode = Mode::OutputOnly;
else if (arg == "trace")
mode = Mode::Trace;
else if (arg == "test")
mode = Mode::Test;
else if (inputFile.empty())
inputFile = arg; // Assign input file name only once.
else
{
cerr << "Unknown argument: " << arg << '\n';
return -1;
}
}
po::store(po::parse_command_line(ac, argv, allowedOptions), vm);
po::notify(vm);
if (vm.count("help")) {
cout << allowedOptions;
Expand Down Expand Up @@ -236,30 +276,7 @@ int main(int argc, char** argv)
data = fromHex(vm["input"].as<string>());
if (vm.count("code"))
code = fromHex(vm["code"].as<string>());
for (int i = 1; i < argc; ++i)
{
string arg = argv[i];
if ((i + 1 < argc && (arg == "--vm" || arg == "--sender" ||
arg == "--origin" || arg == "--gas" || arg == "--gas-price" || arg == "--author" || arg == "--number" ||
arg == "--difficulty" || arg == "--timestamp" || arg == "--gas-limit" || arg == "--value" || arg == "--network"||
arg == "--input" || arg == "--code")) || arg == "--mnemonics" || arg == "--flat")
continue;
else if (arg == "stats")
mode = Mode::Statistics;
else if (arg == "output")
mode = Mode::OutputOnly;
else if (arg == "trace")
mode = Mode::Trace;
else if (arg == "test")
mode = Mode::Test;
else if (inputFile.empty())
inputFile = arg; // Assign input file name only once.
else
{
cerr << "Unknown argument: " << arg << '\n';
return -1;
}
}


VMFactory::setKind(vmKind);

Expand Down