cli20 0.1.2
A C++20 typed-schema command-line parser
Loading...
Searching...
No Matches
parser_stdio.hh
Go to the documentation of this file.
1#pragma once
2
3#include <cstdio>
4#include <cstdlib>
5
6#include "cli/parser.hh"
7
8namespace cli {
9
17template <ArgumentSpec T>
18// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays)
19auto parse_or_exit(int argc, char* argv[], FILE* out, FILE* err) -> T {
20 auto result = parse<T>(argc, argv);
21 if (!result) {
22 if (const auto message = result.error.message(); !message.empty()) {
23 detail::write_message(result.error.use_stdout() ? out : err, message);
24 }
25 std::exit(result.error.exit_code());
26 }
27 return std::move(result.value);
28}
29
30} // namespace cli
Definition action.hh:29
auto parse_or_exit(int argc, char *argv[]) -> T
Parses argc/argv and exits the process on failure.
Definition parser.hh:1488
auto parse(int argc, char *argv[]) -> ParseResult< T >
Convenience free function that parses argc/argv into type T.
Definition parser.hh:1464