Radix Relay
Hybrid mesh communications with Signal Protocol encryption
Loading...
Searching...
No Matches
cli_parser.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <CLI/CLI.hpp>
5#include <spdlog/spdlog.h>
6#include <string>
7
9
14{
15 std::string identity_path = "~/.radix/identity.db";
16 std::string mode = "hybrid";
17 std::string ui_mode = "gui";
18 bool verbose = false;
19 bool show_version = false;
20
21 bool send_parsed = false;
22 std::string send_recipient;
23 std::string send_message;
24
25 bool peers_parsed = false;
26 bool status_parsed = false;
27};
28
35inline auto setup_cli_app(CLI::App &app, cli_args &args) -> void;
36
44[[nodiscard]] inline auto parse_cli_args(int argc, char **argv) -> cli_args
45{
46 cli_args args;
47 CLI::App app{ "Radix Relay - Hybrid Mesh Communications", "radix-relay" };
48
49 setup_cli_app(app, args);
50
51 try {
52 app.parse(argc, argv);
53 } catch (const CLI::ParseError &e) {
54 app.exit(e);
55 std::exit(e.get_exit_code());// NOLINT(concurrency-mt-unsafe)
56 }
57
59
60 return args;
61}
62
63inline auto setup_cli_app(CLI::App &app, cli_args &args) -> void
64{
65 app.add_option("-i,--identity", args.identity_path, "Path to identity key file");
66 app.add_option("-m,--mode", args.mode, "transport mode: internet, mesh, hybrid")
67 ->check(CLI::IsMember({ "internet", "mesh", "hybrid" }));
68 app.add_option("-u,--ui", args.ui_mode, "UI mode: tui, gui")->check(CLI::IsMember({ "tui", "gui" }));
69 app.add_flag("-v,--verbose", args.verbose, "Enable verbose logging");
70 app.add_flag("--version", args.show_version, "Show version information");
71
72 auto *send_cmd = app.add_subcommand("send", "Send a message");
73 send_cmd->add_option("recipient", args.send_recipient, "Node ID or contact name")->required();
74 send_cmd->add_option("message", args.send_message, "Message content")->required();
75 send_cmd->callback([&args]() { args.send_parsed = true; });
76
77 auto *peers_cmd = app.add_subcommand("peers", "List discovered peers");
78 peers_cmd->callback([&args]() { args.peers_parsed = true; });
79
80 auto *status_cmd = app.add_subcommand("status", "Show network status");
81 status_cmd->callback([&args]() { args.status_parsed = true; });
82}
83
90[[nodiscard]] inline auto validate_cli_args(const cli_args &args) -> bool
91{
92 if (args.mode != "internet" and args.mode != "mesh" and args.mode != "hybrid") {
93 spdlog::error("Invalid mode: {}", args.mode);
94 return false;
95 }
96
97 if (args.ui_mode != "tui" and args.ui_mode != "gui") {
98 spdlog::error("Invalid UI mode: {}", args.ui_mode);
99 return false;
100 }
101
102 if (args.send_parsed) {
103 if (args.send_recipient.empty()) {
104 spdlog::error("Send command requires recipient");
105 return false;
106 }
107 if (args.send_message.empty()) {
108 spdlog::error("Send command requires message");
109 return false;
110 }
111 }
112
113 return true;
114}
115
116}// namespace radix_relay::cli_utils
auto setup_cli_app(CLI::App &app, cli_args &args) -> void
Configures CLI11 application with command-line options.
auto validate_cli_args(const cli_args &args) -> bool
Validates parsed command-line arguments for logical consistency.
auto parse_cli_args(int argc, char **argv) -> cli_args
Parses command-line arguments into a cli_args structure.
auto expand_tilde_path(const std::string &path) -> std::string
Expands tilde (~) in path to home directory.
Parsed command-line arguments.
std::string identity_path
Path to identity database file.
bool show_version
Display version and exit.
std::string mode
Transport mode (internet/mesh/hybrid)
std::string ui_mode
UI mode (tui/gui)
bool peers_parsed
True if peers subcommand was used.
std::string send_message
Message content for send subcommand.
bool status_parsed
True if status subcommand was used.
bool send_parsed
True if send subcommand was used.
std::string send_recipient
Recipient for send subcommand.
bool verbose
Enable verbose logging.