Merge pull request #1651 from majestrate/lokinet-bootstrap-help-messages-2021-05-18

add --help and -h flags to lokinet-bootstrap to show help message
This commit is contained in:
Jason Rhinelander 2021-09-08 19:56:32 -03:00 committed by GitHub
commit dbea1f98e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 1 deletions

View File

@ -9,6 +9,7 @@
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#ifndef _WIN32
#include <openssl/x509.h>
@ -28,6 +29,26 @@ namespace
std::cout << msg << std::endl;
return 1;
}
int
print_help(std::string exe)
{
std::cout << R"(Lokinet bootstrap.signed fetchy program thing
Downloads the initial bootstrap.signed for lokinet into a local file from a
default or user defined server via the reachable network.
Usage: )" << exe
<< R"( [bootstrap_url [output_file]]
bootstrap_url can be specified as a full URL, or a special named value
("mainnet" or "testnet") to download from the pre-defined mainnet or testnet
bootstrap URLs.
)";
return 0;
}
} // namespace
int
@ -42,6 +63,15 @@ main(int argc, char* argv[])
std::string bootstrap_url = bootstrap_urls.at("lokinet");
fs::path outputfile{llarp::GetDefaultBootstrap()};
const std::unordered_set<std::string> help_args = {"-h", "--help"};
for (int idx = 1; idx < argc; idx++)
{
const std::string arg{argv[idx]};
if (help_args.count(arg))
return print_help(argv[0]);
}
if (argc > 1)
{
if (auto itr = bootstrap_urls.find(argv[1]); itr != bootstrap_urls.end())
@ -57,7 +87,7 @@ main(int argc, char* argv[])
{
outputfile = fs::path{argv[2]};
}
std::cout << "fetching " << bootstrap_url << std::endl;
cpr::Response resp =
#ifdef _WIN32
cpr::Get(
@ -79,6 +109,7 @@ main(int argc, char* argv[])
{
try
{
std::cout << "writing bootstrap file to: " << outputfile << std::endl;
fs::ofstream ofs{outputfile, std::ios::binary};
ofs.exceptions(fs::ofstream::failbit);
ofs << data;