You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CBLib/include/cb/argparser/argument.h

65 lines
992 B
C++

#ifndef CBLIB_ARGUMENT_H
#define CBLIB_ARGUMENT_H
#include <string>
#include <cassert>
namespace cb::argparser {
enum class Mode {
POSITIONAL,
REQUIRED,
OPTIONAL,
};
enum class Type {
STRING,
BOOL,
INTEGER,
};
struct ParseArgument {
std::string short_name;
std::string name;
std::string description;
std::string default_value;
Type type;
Mode mode;
bool is_present{false};
};
class Argument {
private:
std::string content;
Type type{Type::STRING};
public:
Argument() = default;
explicit Argument(std::string content, Type type = Type::STRING);
[[nodiscard]] const std::string &as_str() const {
return content;
}
[[nodiscard]] bool as_bool() const {
return !content.empty();
}
int as_int() {
assert(type == Type::INTEGER);
return std::stoi(content);
}
explicit operator bool() const {
return as_bool();
}
};
}
#endif //CBLIB_ARGUMENT_H