argon 0.12.0
Command line argument parser
Loading...
Searching...
No Matches
Option.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <argon/Argument.hpp>
4
5#include <functional>
6#include <set>
7#include <string_view>
8#include <vector>
9
10namespace argon {
11
13
16class ARGON_EXPORT Option : public Argument {
17 std::set<std::string> m_flags;
18 std::set<char> m_aliases;
19
20protected:
21 Option(const std::string& flags, const std::string& description);
22 [[nodiscard]] auto flags() const -> std::vector<std::string>;
23
24public:
25 [[nodiscard]] auto format() const -> std::string override;
26 virtual void find(std::vector<std::string_view>& args) const = 0;
27};
28
31class ARGON_EXPORT BasicOption final : public Option {
32 std::function<void()> m_callback;
33
34public:
35 BasicOption(const std::string& flags, const std::string& description, std::function<void()> callback);
36 void find(std::vector<std::string_view>& args) const override;
37};
38
41class ARGON_EXPORT ValueOption final : public Option {
42 std::function<void(std::string_view)> m_callback;
43
44public:
45 ValueOption(const std::string& flags,
46 const std::string& description,
47 std::function<void(std::string_view)> callback);
48 [[nodiscard]] auto format() const -> std::string override;
49 void find(std::vector<std::string_view>& args) const override;
50};
51
52}
Base type of all arguments.
Definition Argument.hpp:14
Optional argument with a simple binary state.
Definition Option.hpp:31
Base type of all optional arguments.
Definition Option.hpp:16
Optional argument with an arbitrary value.
Definition Option.hpp:41