-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For #442.
- Loading branch information
Showing
36 changed files
with
920 additions
and
376 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
.DS_Store | ||
CMakeUserPresets.json | ||
config.json | ||
src/main/impl/Build.cpp | ||
src/util/build/Build.cpp |
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,4 @@ | ||
add_library(clio_app) | ||
target_sources(clio_app PRIVATE CliArgs.cpp ClioApplication.cpp) | ||
|
||
target_link_libraries(clio_app PUBLIC clio_etl clio_feed clio_web clio_rpc) |
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,70 @@ | ||
//------------------------------------------------------------------------------ | ||
/* | ||
This file is part of clio: https://github.com/XRPLF/clio | ||
Copyright (c) 2024, the clio developers. | ||
Permission to use, copy, modify, and distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
//============================================================================== | ||
|
||
#include "app/CliArgs.hpp" | ||
|
||
#include "util/build/Build.hpp" | ||
|
||
#include <boost/program_options/options_description.hpp> | ||
#include <boost/program_options/parsers.hpp> | ||
#include <boost/program_options/positional_options.hpp> | ||
#include <boost/program_options/value_semantic.hpp> | ||
#include <boost/program_options/variables_map.hpp> | ||
|
||
#include <cstdlib> | ||
#include <iostream> | ||
#include <string> | ||
#include <utility> | ||
|
||
namespace app { | ||
|
||
CliArgs::Action | ||
CliArgs::parse(int argc, char const* argv[]) | ||
{ | ||
namespace po = boost::program_options; | ||
// clang-format off | ||
po::options_description description("Options"); | ||
description.add_options() | ||
("help,h", "print help message and exit") | ||
("version,v", "print version and exit") | ||
("conf,c", po::value<std::string>()->default_value(defaultConfigPath), "configuration file") | ||
; | ||
// clang-format on | ||
po::positional_options_description positional; | ||
positional.add("conf", 1); | ||
|
||
po::variables_map parsed; | ||
po::store(po::command_line_parser(argc, argv).options(description).positional(positional).run(), parsed); | ||
po::notify(parsed); | ||
|
||
if (parsed.count("help") != 0u) { | ||
std::cout << "Clio server " << util::build::getClioFullVersionString() << "\n\n" << description; | ||
return Action{Action::Exit{EXIT_SUCCESS}}; | ||
} | ||
|
||
if (parsed.count("version") != 0u) { | ||
std::cout << util::build::getClioFullVersionString() << '\n'; | ||
return Action{Action::Exit{EXIT_SUCCESS}}; | ||
} | ||
|
||
auto configPath = parsed["conf"].as<std::string>(); | ||
return Action{Action::Run{std::move(configPath)}}; | ||
} | ||
|
||
} // namespace app |
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,96 @@ | ||
//------------------------------------------------------------------------------ | ||
/* | ||
This file is part of clio: https://github.com/XRPLF/clio | ||
Copyright (c) 2024, the clio developers. | ||
Permission to use, copy, modify, and distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
//============================================================================== | ||
|
||
#pragma once | ||
|
||
#include "util/OverloadSet.hpp" | ||
|
||
#include <string> | ||
#include <variant> | ||
|
||
namespace app { | ||
|
||
/** | ||
* @brief Parsed command line arguments representation. | ||
*/ | ||
class CliArgs { | ||
public: | ||
/** | ||
* @brief Default configuration path. | ||
*/ | ||
static constexpr char defaultConfigPath[] = "/etc/opt/clio/config.json"; | ||
|
||
/** | ||
* @brief An action parsed from the command line. | ||
*/ | ||
class Action { | ||
public: | ||
/** @brief Run action. */ | ||
struct Run { | ||
/** @brief Configuration file path. */ | ||
std::string configPath; | ||
}; | ||
|
||
/** @brief Exit action. */ | ||
struct Exit { | ||
/** @brief Exit code. */ | ||
int exitCode; | ||
}; | ||
|
||
/** | ||
* @brief Construct an action from a Run. | ||
* | ||
* @param action Run action. | ||
*/ | ||
template <typename ActionType> | ||
requires std::is_same_v<ActionType, Run> or std::is_same_v<ActionType, Exit> | ||
explicit Action(ActionType&& action) : action_(std::forward<ActionType>(action)) | ||
{ | ||
} | ||
|
||
/** | ||
* @brief Apply a function to the action. | ||
* | ||
* @tparam Processors Action processors types. Must be callable with the action type and return int. | ||
* @param processors Action processors. | ||
* @return Exit code. | ||
*/ | ||
template <typename... Processors> | ||
int | ||
apply(Processors&&... processors) const | ||
{ | ||
return std::visit(util::OverloadSet{std::forward<Processors>(processors)...}, action_); | ||
} | ||
|
||
private: | ||
std::variant<Run, Exit> action_; | ||
}; | ||
|
||
/** | ||
* @brief Parse command line arguments. | ||
* | ||
* @param argc Number of arguments. | ||
* @param argv Array of arguments. | ||
* @return Parsed command line arguments. | ||
*/ | ||
static Action | ||
parse(int argc, char const* argv[]); | ||
}; | ||
|
||
} // namespace app |
Oops, something went wrong.