RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
ParseResult.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5
6namespace RST::Parser {
7
9 enum class ParseStatus : std::uint8_t { Ok, Help, Version, Error };
10
12 struct ParseResult {
15 std::string message;
16
17 [[nodiscard]] explicit operator bool() const noexcept { return status == ParseStatus::Ok; }
19 [[nodiscard]] int exitCode() const noexcept { return status == ParseStatus::Error ? 2 : 0; }
20
22 void print() const;
23 };
24}
Command-line parser with subcommands, typed and validated values and generated help.
Definition ArgParser.hpp:17
ParseStatus
Outcome of ArgParser::parse(); Help and Version mean the user asked for that text.
Definition ParseResult.hpp:9
Result of ArgParser::parse(), true when the arguments are valid.
Definition ParseResult.hpp:12
ParseStatus status
Definition ParseResult.hpp:13
std::string message
Text to print for help, version and errors.
Definition ParseResult.hpp:15
void print() const
Prints the message, to stderr for errors and stdout otherwise.
int exitCode() const noexcept
Exit code for main: 2 for errors, 0 otherwise.
Definition ParseResult.hpp:19