lintel 0.2.0
Loading...
Searching...
No Matches
Command.h
Go to the documentation of this file.
1#ifndef LINTEL_COMMAND_H
2#define LINTEL_COMMAND_H
3
4#include <cstdint>
5#include <iostream>
6#include <map>
7#include <optional>
8#include <string>
9#include <variant>
10#include <vector>
11
12namespace lintel {
15{
16public:
17 // These are the possible variables the options may point to. Bool and
18 // std::string are handled in a special way, all other values are parsed
19 // with a std::stringstream. This std::variant can be easily extended if
20 // the stream operator>> is overloaded. If not, you have to add a special
21 // case to the parse() method.
22 using Value = std::variant<int32_t *,
23 uint32_t *,
24 double *,
25 float *,
26 bool *,
27 std::string *,
28 std::vector<std::string> *,
29 std::optional<int32_t> *,
30 std::optional<uint32_t> *,
31 std::optional<double> *,
32 std::optional<float> *,
33 std::optional<bool> *,
34 std::optional<std::string> *>;
35
38 Command(std::string command, std::string description);
39
51 Command &addArgument(const std::vector<std::string> &flags,
53 const std::string &help,
54 bool optional = false);
55
57 Command &
58 addArgument(const std::vector<std::string> &&flags, Value defaultValue, std::string help, bool optional = false);
59
61 void printHelp(std::ostream &os = std::cout) const;
62
64 [[nodiscard]] std::string getCommand() const;
65
73 void parse(const std::string &command, const std::vector<std::string> &flags) const;
74
76 void resetOptionals() const;
77
79 static void parseValueFromStream(const std::string &value, const Value &m_value);
80
81private:
82 struct Argument
83 {
84 std::vector<std::string> m_flags;
85 Value m_value;
86 std::string m_help;
87 bool m_optional;
88 };
89
90 std::string m_command;
91 std::string m_description;
92 std::map<std::string, Argument> m_argumentsMap;
93 std::vector<Argument> m_arguments;
94 static constexpr const char *m_tab = "\t";
95};
96
97}// namespace lintel
98#endif// LINTEL_COMMAND_H
Definition Command.h:15
Command & addArgument(const std::vector< std::string > &flags, Value defaultValue, const std::string &help, bool optional=false)
Command(std::string command, std::string description)
Command & addArgument(const std::vector< std::string > &&flags, Value defaultValue, std::string help, bool optional=false)
void printHelp(std::ostream &os=std::cout) const
std::variant< int32_t *, uint32_t *, double *, float *, bool *, std::string *, std::vector< std::string > *, std::optional< int32_t > *, std::optional< uint32_t > *, std::optional< double > *, std::optional< float > *, std::optional< bool > *, std::optional< std::string > * > Value
Definition Command.h:34
void resetOptionals() const
static void parseValueFromStream(const std::string &value, const Value &m_value)
std::string getCommand() const
void parse(const std::string &command, const std::vector< std::string > &flags) const
Definition BaseFeature.h:6
constexpr std::string_view type_name()
Definition TypeName.h:9