5#include <portals/ui_app.hpp>
7#include <lyra/lyra.hpp>
12namespace portals::ui::lyra {
32inline CommandLineParser cli(::lyra::cli parser, CliOptions options = {}) {
33 return [parser = std::move(parser), options = std::move(options)](
34 const app::Arguments &arguments) -> std::expected<LaunchAction, CommandLineError> {
37 auto invocation = parser;
39 if (options.automaticHelp) {
40 invocation |= ::lyra::help(showHelp);
43 if (!options.version.empty()) {
44 invocation |= ::lyra::opt([&showVersion](
bool flag) {
47 return ::lyra::parser_result::ok(::lyra::parser_result_type::short_circuit_all);
48 })[
"--version"](
"Display version information.");
51 const auto result = invocation.parse(::lyra::args(arguments.begin(), arguments.end()));
54 return std::unexpected(CommandLineError{CommandLineErrorCode::INVALID_ARGUMENT, result.message()});
57 if (showHelp || (options.helpRequested && *options.helpRequested)) {
58 std::ostringstream output;
62 return LaunchAction{LaunchDisposition::FINISH, std::move(output).str()};
66 return LaunchAction{LaunchDisposition::FINISH, options.version +
'\n'};
69 return LaunchAction{};
Optional built-in launch actions; parsing itself remains Lyra's responsibility.
Definition ui_lyra.hpp:15
const bool * helpRequested
Optional caller-owned custom help flag; must outlive invocation.
Definition ui_lyra.hpp:18
bool automaticHelp
Add Lyra's -?, -h and –help; disable when supplying custom help.
Definition ui_lyra.hpp:16
std::string version
Nonempty text enables a short-circuiting –version option.
Definition ui_lyra.hpp:17