/* * Copyright (c) 2020, Sergey Bugaev * Copyright (c) 2023, Ali Mohammad Pur * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace AK { class OptionParser { public: enum class ArgumentRequirement { NoArgument, HasOptionalArgument, HasRequiredArgument, }; // Note: This is weird, but this class is used as a backend for getopt, so we're mirroring getopt here. struct Option { StringView name; ArgumentRequirement requirement; int* flag; int val; }; struct GetOptResult { int result; // Whatever getopt is supposed to return. Optional optopt_value; // The new contents of `optopt' after this call Optional optarg_value; // The new contents of `optarg' after this call size_t consumed_args; }; GetOptResult getopt(Span args, StringView short_options, Span