diff --git a/Inc/argparser.h b/Inc/argparser.h index a445450..bd53d26 100644 --- a/Inc/argparser.h +++ b/Inc/argparser.h @@ -7,12 +7,14 @@ namespace Arguments enum ERROR { NO_ERROR = 0, + ERROR_UNKNOWN_ARGUMENT, ERROR_UNKNOWN_POSITIONAL_ARGUMENT, + ERROR_MISSING_VALUE, ERROR_MISSING_POSITIONAL_ARGUMENT, + ERROR_INVALID_INT, - SPECIAL_CASE_HELP, }; class Parser @@ -38,8 +40,6 @@ public: Argument(const char* name); Argument(char name); - Argument& description(const char* desc); - Argument& alias(const char* alias); Argument& alias(char alias); @@ -56,8 +56,6 @@ protected: const char* m_Name; char m_ShortName; - const char* m_Description; - private: std::vector m_Aliases; std::vector m_ShortAliases; @@ -112,16 +110,11 @@ class PositionalArgument public: PositionalArgument(bool required); - void description(const char* desc); - virtual ERROR parseValue(Parser& state) = 0; public: bool found; bool required; - -private: - const char* m_Description; }; diff --git a/README.md b/README.md new file mode 100644 index 0000000..5c710af --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# v2 + +I never really liked the interface of v1, so after coming back to this project, I spent some time thinking about how it could be improved, +took some inspiration from Golangs flag module, and made v2, which has a simpler, more flexible interface with better type safety + +For example: + - It doesn't cast char* to uint64_t and require you to cast it back + - It doesn't require you to create a parser object, you just call parse + - You don't have to add the arguments to that parser object, it's taken care of just by calling the constructor + - You aren't required to provide descriptions for you program and every argument + +That last one means that v2 will _not_ take care of --help and -h for you. If you want a help menu, you have to create it yourself. +But help menus aren't always required and when you do want one, this gives you control over what it looks like + + +# How do I use this + +Check out [test.cpp](test.cpp). It demonstrates the full scope of this library + diff --git a/Src/argparser.cpp b/Src/argparser.cpp index cf77301..771efab 100644 --- a/Src/argparser.cpp +++ b/Src/argparser.cpp @@ -51,12 +51,6 @@ Argument::Argument(char name) arguments.push_back(this); }; -Argument& Argument::description(const char* desc) -{ - m_Description = desc; - return *this; -} - Argument& Argument::alias(const char* alias) { m_Aliases.push_back(alias); @@ -223,7 +217,7 @@ ERROR Bool::parseValue(Parser& state) PositionalArgument::PositionalArgument(bool required) - : found(false), required(required), m_Description(nullptr) + : found(false), required(required) { if (required) { for (PositionalArgument* arg: positionalArguments) { @@ -237,12 +231,6 @@ PositionalArgument::PositionalArgument(bool required) positionalArguments.push_back(this); } -void PositionalArgument::description(const char* desc) -{ - m_Description = desc; -} - - PositionalInt::PositionalInt(int64_t defaultValue, bool required) : PositionalArgument(required), value(defaultValue) { } diff --git a/test.cpp b/test.cpp index 7770b49..e077044 100644 --- a/test.cpp +++ b/test.cpp @@ -5,13 +5,13 @@ int main(int argc, char** argv) { Arguments::String first('f', "none"); - first.description("First arg"); + first.alias("first"); Arguments::Int second("second", 0); - second.description("Second arg").alias('s'); + second.alias('s'); Arguments::Bool third("third"); - third.description("Third arg").alias("abc").alias('t'); + third.alias("abc").alias('t'); Arguments::PositionalString name("", true); Arguments::PositionalInt age(0, false);