-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to config generation branch based on merge comments
Signed-off-by: Yiannis Karavas <[email protected]>
- Loading branch information
Showing
6 changed files
with
158 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) 2022 MIT Digital Currency Initiative, | ||
// Federal Reserve Bank of Boston | ||
// MITRE Corporation | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include "config_generator.hpp" | ||
|
||
#include <iostream> | ||
#include <random> | ||
|
||
auto main(int argc, char** argv) -> int { | ||
auto args = cbdc::config::get_args(argc, argv); | ||
|
||
std::mt19937 rng; | ||
static const auto m_random_source | ||
= std::make_unique<cbdc::random_source>(cbdc::config::random_source); | ||
|
||
std::string build_dir = "build"; | ||
size_t max_param_num = 4; | ||
size_t min_param_num = 3; | ||
if(args.size() == 2 && (args[1] == "-h" || args[1] == "--help")) { | ||
std::cout << "Usage: " << args[0] | ||
<< " <config template file> <starting port number to " | ||
"increment from> <build directory name, using '/' as " | ||
"separator. (defaults to 'build')>" | ||
<< std::endl; | ||
return 0; | ||
} else if(args.size() < min_param_num) { | ||
std::cerr << "Usage: " << args[0] | ||
<< " <config template file> <starting port number to " | ||
"increment from> <build directory name, using '/' as " | ||
"separator. (defaults to 'build')>" | ||
<< std::endl; | ||
return 0; | ||
} else if(args.size() == min_param_num) { | ||
std::cout << "No build directory name specified as third. Using " | ||
"default name of 'build'" | ||
<< std::endl; | ||
} else if(args.size() == max_param_num) { | ||
build_dir = args[max_param_num - 1]; | ||
} else if(args.size() > max_param_num) { | ||
std::cerr << "Too many parameters input. Usage: " << args[0] | ||
<< " <config template file> <starting port number to " | ||
"increment from> <build directory name, using '/' as " | ||
"separator. (defaults to 'build')>" | ||
<< std::endl; | ||
return 0; | ||
} | ||
|
||
auto port_is_valid = std::isdigit(*args[2].c_str()); | ||
if(!port_is_valid) { | ||
std::cerr << "Port number provided, " << args[2] | ||
<< ", is not a valid number. Exiting..." << std::endl; | ||
return 0; | ||
} | ||
size_t port_num = static_cast<size_t>(std::stoull(args[2])); | ||
if(port_num > MAX_PORT_NUM) { | ||
std::cerr << "Port number provided, " << args[2] | ||
<< ", is too large. Exiting..." << std::endl; | ||
return 0; | ||
} | ||
cbdc::generate_config::config_generator new_config_gen(args[1], | ||
port_num, | ||
build_dir); | ||
auto cfg_or_err = new_config_gen.generate_configuration_file(); | ||
std::cout << cfg_or_err << std::endl; | ||
return 0; | ||
} |
Oops, something went wrong.