libcruft-util/cmdopt2/parser.hpp

40 lines
1.0 KiB
C++
Raw Normal View History

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2022, Danny Robson <danny@nerdcruft.net>
*/
#pragma once
#include "./fwd.hpp"
#include <iosfwd>
#include <vector>
namespace cruft::cmdopt2 {
class parser {
public:
explicit parser (char const *desc);
2022-03-18 16:04:45 +11:00
int parse [[nodiscard]] (int argc, char const* const* argv);
positional_t& add (positional_t const&) &;
keyword_t& add (keyword_t const&) &;
void usage (int argc, char const * const* argv, FILE*) const;
private:
2022-03-18 16:04:45 +11:00
int parse_named (int argc, char const* const* argv, int*) const;
int parse_short (int argc, char const* const* argv, int*) const;
int parse_long (int argc, char const* const* argv, int*) const;
std::vector<positional_t> m_positional;
std::vector<keyword_t> m_keyword;
char const *m_description;
};
}