Luna/libos/include/os/ArgumentParser.h

52 lines
1.4 KiB
C
Raw Normal View History

#pragma once
#include <luna/StringView.h>
#include <luna/Vector.h>
namespace os
{
class ArgumentParser
{
public:
ArgumentParser() = default;
Result<void> add_positional_argument(StringView& out, StringView name, bool required);
Result<void> add_positional_argument(StringView& out, StringView name, StringView fallback);
Result<void> add_switch_argument(bool& out, char short_flag, StringView long_flag);
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);
Result<Vector<StringView>> parse(int argc, char* const* argv);
private:
struct PositionalArgument
{
StringView* out;
StringView name;
bool required;
StringView fallback;
};
struct SwitchArgument
{
bool* out;
char short_flag;
StringView long_flag;
};
struct ValueArgument
{
StringView* out;
char short_flag;
StringView long_flag;
bool required;
StringView fallback;
};
Vector<PositionalArgument> m_positional_args;
Vector<SwitchArgument> m_switch_args;
Vector<ValueArgument> m_value_args;
};
}