koutil
Loading...
Searching...
No Matches
result.h
Go to the documentation of this file.
1#ifndef KOUTIL_ARGS_RESULT_H
2#define KOUTIL_ARGS_RESULT_H
3
4#include <concepts>
5#include <string>
6#include <utility>
7#include <vector>
8
9namespace koutil::args {
10
19public:
20 result_base_t() = default;
21
26 [[nodiscard]] bool has_error() const { return !m_errors.empty(); }
27
34 [[nodiscard]] bool need_exit() const { return m_exit; }
35
40 [[nodiscard]] const auto& errors() const { return m_errors; }
41
46 void add_error(std::string error) { m_errors.emplace_back(std::move(error)); }
47
52 void exit() { m_exit = true; }
53
54private:
55 bool m_exit = false;
56 std::vector<std::string> m_errors;
57};
58
59template <typename T>
60concept extends_result = std::derived_from<T, result_base_t>;
61
62}
63
64#endif
Represents the result of command-line parsing.
Definition result.h:18
const auto & errors() const
Returns the list of error messages.
Definition result.h:40
std::vector< std::string > m_errors
Definition result.h:56
bool need_exit() const
Checks if the parser requested program exit.
Definition result.h:34
bool has_error() const
Checks if any errors occurred.
Definition result.h:26
void add_error(std::string error)
Adds an error message.
Definition result.h:46
void exit()
Marks the result as requiring exit.
Definition result.h:52
bool m_exit
Definition result.h:55
Definition result.h:60
Definition argument.h:9