mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
using boost::program_options for argument parsing
This commit is contained in:
parent
1f209f1b7d
commit
d4d0b07c35
@ -8,6 +8,7 @@ set(EXECUTABLE solc)
|
|||||||
|
|
||||||
add_executable(${EXECUTABLE} ${SRC_LIST})
|
add_executable(${EXECUTABLE} ${SRC_LIST})
|
||||||
|
|
||||||
|
target_link_libraries(${EXECUTABLE} boost_program_options)
|
||||||
target_link_libraries(${EXECUTABLE} solidity)
|
target_link_libraries(${EXECUTABLE} solidity)
|
||||||
|
|
||||||
install( TARGETS ${EXECUTABLE} DESTINATION bin )
|
install( TARGETS ${EXECUTABLE} DESTINATION bin )
|
||||||
|
59
main.cpp
59
main.cpp
@ -23,6 +23,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
|
#include "BuildInfo.h"
|
||||||
#include <libdevcore/Common.h>
|
#include <libdevcore/Common.h>
|
||||||
#include <libdevcore/CommonData.h>
|
#include <libdevcore/CommonData.h>
|
||||||
#include <libdevcore/CommonIO.h>
|
#include <libdevcore/CommonIO.h>
|
||||||
@ -38,43 +41,45 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace dev;
|
using namespace dev;
|
||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
|
namespace po = boost::program_options;
|
||||||
void help()
|
|
||||||
{
|
|
||||||
cout << "Usage solc [OPTIONS] <file>" << endl
|
|
||||||
<< "Options:" << endl
|
|
||||||
<< " -o,--optimize Optimize the bytecode for size." << endl
|
|
||||||
<< " -h,--help Show this help message and exit." << endl
|
|
||||||
<< " -V,--version Show the version and exit." << endl;
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void version()
|
void version()
|
||||||
{
|
{
|
||||||
cout << "solc, the solidity complier commandline interface " << dev::Version << endl
|
cout << "solc, the solidity complier commandline interface " << dev::Version << endl
|
||||||
<< " by Christian <c@ethdev.com>, (c) 2014." << endl
|
<< " by Christian <c@ethdev.com> and Lefteris <lefteris@ethdev.com>, (c) 2014." << endl
|
||||||
<< "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << endl;
|
<< "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << endl;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
vector<string> infiles;
|
// Declare the supported options.
|
||||||
bool optimize = false;
|
po::options_description desc("Allowed options");
|
||||||
for (int i = 1; i < argc; ++i)
|
desc.add_options()
|
||||||
{
|
("help", "Show help message and exit")
|
||||||
string arg = argv[i];
|
("version", "Show version and exit")
|
||||||
if (arg == "-o" || arg == "--optimize")
|
("optimize", po::value<bool>()->default_value(false), "Optimize bytecode for size")
|
||||||
optimize = true;
|
("input-file", po::value<vector<string>>(), "input file");
|
||||||
else if (arg == "-h" || arg == "--help")
|
|
||||||
help();
|
// All positional options should be interpreted as input files
|
||||||
else if (arg == "-V" || arg == "--version")
|
po::positional_options_description p;
|
||||||
version();
|
p.add("input-file", -1);
|
||||||
else
|
|
||||||
infiles.push_back(argv[i]);
|
po::variables_map vm;
|
||||||
|
po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
|
||||||
|
po::notify(vm);
|
||||||
|
|
||||||
|
if (vm.count("help")) {
|
||||||
|
cout << desc;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vm.count("version")) {
|
||||||
|
version();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
map<string, string> sourceCodes;
|
map<string, string> sourceCodes;
|
||||||
if (infiles.empty())
|
if (!vm.count("input-file"))
|
||||||
{
|
{
|
||||||
string s;
|
string s;
|
||||||
while (!cin.eof())
|
while (!cin.eof())
|
||||||
@ -84,7 +89,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
for (string const& infile: infiles)
|
for (string const& infile: vm["input-file"].as<vector<string>>())
|
||||||
sourceCodes[infile] = asString(dev::contents(infile));
|
sourceCodes[infile] = asString(dev::contents(infile));
|
||||||
|
|
||||||
CompilerStack compiler;
|
CompilerStack compiler;
|
||||||
@ -92,7 +97,7 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
for (auto const& sourceCode: sourceCodes)
|
for (auto const& sourceCode: sourceCodes)
|
||||||
compiler.addSource(sourceCode.first, sourceCode.second);
|
compiler.addSource(sourceCode.first, sourceCode.second);
|
||||||
compiler.compile(optimize);
|
compiler.compile( vm["optimize"].as<bool>());
|
||||||
}
|
}
|
||||||
catch (ParserError const& exception)
|
catch (ParserError const& exception)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user