2023-03-29 16:27:02 +00:00
|
|
|
#pragma once
|
|
|
|
#include <luna/StringView.h>
|
|
|
|
#include <luna/Vector.h>
|
|
|
|
|
|
|
|
class ArgumentParser
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ArgumentParser() = default;
|
|
|
|
|
|
|
|
Result<void> add_positional_argument(StringView& out, StringView name, bool required);
|
2023-03-29 19:46:07 +00:00
|
|
|
Result<void> add_positional_argument(StringView& out, StringView name, StringView fallback);
|
2023-03-29 16:27:02 +00:00
|
|
|
|
2023-03-29 17:25:11 +00:00
|
|
|
Result<void> add_switch_argument(bool& out, char short_flag, StringView long_flag);
|
|
|
|
|
2023-03-29 19:46:07 +00:00
|
|
|
Result<void> add_value_argument(StringView& out, char short_flag, StringView long_flag, bool value_required);
|
|
|
|
Result<void> add_value_argument(StringView& out, char short_flag, StringView long_flag, StringView fallback);
|
|
|
|
|
2023-03-29 16:27:02 +00:00
|
|
|
void parse(int argc, char* const* argv);
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct PositionalArgument
|
|
|
|
{
|
|
|
|
StringView* out;
|
|
|
|
StringView name;
|
|
|
|
bool required;
|
|
|
|
StringView fallback;
|
|
|
|
};
|
|
|
|
|
2023-03-29 17:25:11 +00:00
|
|
|
struct SwitchArgument
|
|
|
|
{
|
|
|
|
bool* out;
|
|
|
|
char short_flag;
|
|
|
|
StringView long_flag;
|
|
|
|
};
|
|
|
|
|
2023-03-29 19:46:07 +00:00
|
|
|
struct ValueArgument
|
|
|
|
{
|
|
|
|
StringView* out;
|
|
|
|
char short_flag;
|
|
|
|
StringView long_flag;
|
|
|
|
bool required;
|
|
|
|
StringView fallback;
|
|
|
|
};
|
|
|
|
|
2023-03-29 16:27:02 +00:00
|
|
|
Vector<PositionalArgument> m_positional_args;
|
2023-03-29 17:25:11 +00:00
|
|
|
Vector<SwitchArgument> m_switch_args;
|
2023-03-29 19:46:07 +00:00
|
|
|
Vector<ValueArgument> m_value_args;
|
2023-03-29 16:27:02 +00:00
|
|
|
};
|