Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
CliArgs.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "migration/MigrationApplication.hpp"
23#include "util/OverloadSet.hpp"
24
25#include <string>
26#include <variant>
27
28namespace app {
29
33class CliArgs {
34public:
38 static constexpr char kDEFAULT_CONFIG_PATH[] = "/etc/opt/clio/config.json";
39
43 class Action {
44 public:
46 struct Run {
47 std::string configPath;
49 };
50
52 struct Exit {
54 };
55
57 struct Migrate {
58 std::string configPath;
59 MigrateSubCmd subCmd;
60 };
61
63 struct VerifyConfig {
64 std::string configPath;
65 };
66
72 template <typename ActionType>
73 requires std::is_same_v<ActionType, Run> or std::is_same_v<ActionType, Exit> or
74 std::is_same_v<ActionType, Migrate> or std::is_same_v<ActionType, VerifyConfig>
75 explicit Action(ActionType&& action) : action_(std::forward<ActionType>(action))
76 {
77 }
78
86 template <typename... Processors>
87 int
88 apply(Processors&&... processors) const
89 {
90 return std::visit(util::OverloadSet{std::forward<Processors>(processors)...}, action_);
91 }
92
93 private:
94 std::variant<Run, Exit, Migrate, VerifyConfig> action_;
95 };
96
104 static Action
105 parse(int argc, char const* argv[]);
106};
107
108} // namespace app
An action parsed from the command line.
Definition CliArgs.hpp:43
int apply(Processors &&... processors) const
Apply a function to the action.
Definition CliArgs.hpp:88
Action(ActionType &&action)
Construct an action from a Run.
Definition CliArgs.hpp:75
Parsed command line arguments representation.
Definition CliArgs.hpp:33
static Action parse(int argc, char const *argv[])
Parse command line arguments.
Definition CliArgs.cpp:41
static constexpr char kDEFAULT_CONFIG_PATH[]
Default configuration path.
Definition CliArgs.hpp:38
Exit action.
Definition CliArgs.hpp:52
int exitCode
Exit code.
Definition CliArgs.hpp:53
Migration action.
Definition CliArgs.hpp:57
Run action.
Definition CliArgs.hpp:46
std::string configPath
Configuration file path.
Definition CliArgs.hpp:47
bool useNgWebServer
Whether to use a ng web server.
Definition CliArgs.hpp:48
Verify Config action.
Definition CliArgs.hpp:63
The command to run for migration framework.
Definition MigrationApplication.hpp:34
Overload set for lambdas.
Definition OverloadSet.hpp:30