summaryrefslogtreecommitdiff
path: root/src/args.hh
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-09-03 00:49:27 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-09-03 00:49:27 +0200
commitd75b25d50f4df655d1e69ff900cfeee823039296 (patch)
treee4afe9877021c4c76ffdf8dbbcc25c0c7f1a7f34 /src/args.hh
Initial commit
Only a basic argument parser to start with.
Diffstat (limited to 'src/args.hh')
-rw-r--r--src/args.hh70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/args.hh b/src/args.hh
new file mode 100644
index 0000000..75c31b1
--- /dev/null
+++ b/src/args.hh
@@ -0,0 +1,70 @@
+#ifndef ARGS_HH
+#define ARGS_HH
+
+#include <cstdint>
+#include <iosfwd>
+#include <memory>
+#include <string>
+#include <string_view>
+#include <vector>
+
+class Args {
+ public:
+ virtual ~Args() = default;
+
+ class Option {
+ public:
+ virtual ~Option() = default;
+
+ virtual bool is_set() const = 0;
+
+ protected:
+ Option() = default;
+ Option(Option const&) = delete;
+ Option& operator=(Option const&) = delete;
+ };
+
+ class OptionArgument : public Option {
+ public:
+ virtual bool has_argument() const = 0;
+ virtual const std::string& argument() const = 0;
+ };
+
+ static std::unique_ptr<Args> create(std::string prgname = std::string());
+
+ virtual std::shared_ptr<Option> option(
+ char shortname,
+ std::string longname = std::string(),
+ std::string help = std::string()) = 0;
+
+ std::shared_ptr<Option> option(
+ std::string longname,
+ std::string help = std::string());
+
+ virtual std::shared_ptr<OptionArgument> option_argument(
+ char shortname,
+ std::string longname = std::string(),
+ std::string arg = std::string(),
+ std::string help = std::string(),
+ bool required = true) = 0;
+
+ std::shared_ptr<OptionArgument> option_argument(
+ std::string longname,
+ std::string arg = std::string(),
+ std::string help = std::string(),
+ bool required = true);
+
+ virtual bool run(int argc, char** argv,
+ std::vector<std::string_view>* arguments = nullptr) = 0;
+
+ virtual void print_error(std::ostream& out) const = 0;
+
+ virtual void print_help(std::ostream& out, uint32_t width = 79) const = 0;
+
+ protected:
+ Args() = default;
+ Args(Args const&) = delete;
+ Args& operator=(Args const&) = delete;
+};
+
+#endif // ARGS_HH