/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2019, Google Inc. * * options.cpp - cam - Options parsing */ #include #include #include #include #include #include "options.h" /** * \enum OptionArgument * \brief Indicate if an option takes an argument * * \var OptionArgument::ArgumentNone * \brief The option doesn't accept any argument * * \var OptionArgument::ArgumentRequired * \brief The option requires an argument * * \var OptionArgument::ArgumentOptional * \brief The option accepts an optional argument */ /** * \enum OptionType * \brief The type of argument for an option * * \var OptionType::OptionNone * \brief No argument type, used for options that take no argument * * \var OptionType::OptionInteger * \brief Integer argument type, with an optional base prefix (`0` for base 8, * `0x` for base 16, none for base 10) * * \var OptionType::OptionString * \brief String argument * * \var OptionType::OptionKeyValue * \brief key=value list argument */ /* ----------------------------------------------------------------------------- * Option */ /** * \struct Option * \brief Store metadata about an option * * \var Option::opt * \brief The option identifier * * \var Option::type * \brief The type of the option argument * * \var Option::name * \brief The option name * * \var Option::argument * \brief Whether the option accepts an optional argument, a mandatory * argument, or no argument at all * * \var Option::argumentName * \brief The argument name used in the help text * * \var Option::help * \brief The help text (may be a multi-line string) * * \var Option::keyValueParser * \brief For options of type OptionType::OptionKeyValue, the key-value parser * to parse the argument * * \var Option::isArray * \brief Whether the option can appear once or multiple times * * \var Option::parent * \brief The parent option * * \var Option::children * \brief List of child options, storing all options whose parent is this option * * \fn Option::hasShortOption() * \brief Tell if the option has a short option specifier (e.g. `-f`) * \return True if the option has a short option specifier, false otherwise * * \fn Option::hasLongOption() * \brief Tell if the option has a long option specifier (e.g. `--foo`) * \return True if the option has a long option specifier, false otherwise */ struct Option { int opt; OptionType type; const char *name; OptionArgument argument; const char *argumentName; const char *help; KeyValueParser *keyValueParser; bool isArray; Option *parent; std::list