2015-06-10 21:28:52 +10:00
|
|
|
/*
|
2018-08-04 15:14:06 +10:00
|
|
|
* 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/.
|
2015-06-10 21:28:52 +10:00
|
|
|
*
|
2016-03-15 13:55:49 +11:00
|
|
|
* Copyright 2013-2016 Danny Robson <danny@nerdcruft.net>
|
2015-06-10 21:28:52 +10:00
|
|
|
*/
|
|
|
|
|
2017-11-22 16:49:37 +11:00
|
|
|
#include "cmdopt.hpp"
|
2015-06-10 21:28:52 +10:00
|
|
|
|
2017-11-22 16:49:37 +11:00
|
|
|
#include "cast.hpp"
|
2019-05-17 12:26:08 +10:00
|
|
|
#include "debug/assert.hpp"
|
2015-06-10 21:28:52 +10:00
|
|
|
|
|
|
|
#include <cstring>
|
2016-02-05 14:27:21 +11:00
|
|
|
#include <iostream>
|
2015-09-11 19:55:32 +10:00
|
|
|
#include <iomanip>
|
2015-06-10 21:28:52 +10:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
using namespace cruft::cmdopt;
|
|
|
|
using namespace cruft::cmdopt::option;
|
2015-06-10 21:28:52 +10:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2020-01-17 07:58:23 +11:00
|
|
|
base::base ()
|
|
|
|
: m_required ([] () { return false; })
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2015-06-10 21:28:52 +10:00
|
|
|
base::~base ()
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
base::execute (void)
|
|
|
|
{
|
2016-03-15 13:55:49 +11:00
|
|
|
throw invalid_null ();
|
2015-06-10 21:28:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
2016-03-15 13:55:49 +11:00
|
|
|
base::execute (const char *restrict value)
|
2015-06-10 21:28:52 +10:00
|
|
|
{
|
2016-03-15 13:55:49 +11:00
|
|
|
throw invalid_value (value);
|
2015-06-10 21:28:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
base::start (void)
|
2015-06-30 22:04:54 +10:00
|
|
|
{
|
|
|
|
m_seen = false;
|
|
|
|
}
|
2015-06-10 21:28:52 +10:00
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
base::finish (void)
|
2015-06-30 22:04:54 +10:00
|
|
|
{
|
2020-01-17 07:58:23 +11:00
|
|
|
if (!fulfilled ())
|
2016-03-15 13:55:49 +11:00
|
|
|
throw invalid_required ();
|
2015-09-11 19:55:32 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-17 07:58:23 +11:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
base::required (std::function<bool(void)> _required)
|
|
|
|
{
|
|
|
|
m_required = std::move (_required);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-30 22:04:54 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
base::required (void) const
|
|
|
|
{
|
2020-01-17 07:58:23 +11:00
|
|
|
return m_required ();
|
2015-06-30 22:04:54 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2020-01-17 07:58:23 +11:00
|
|
|
void
|
2015-06-30 22:04:54 +10:00
|
|
|
base::required (bool _required)
|
|
|
|
{
|
2020-01-17 07:58:23 +11:00
|
|
|
m_required = [_required] (void) { return _required; };
|
2015-06-30 22:04:54 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
base::seen (void) const
|
|
|
|
{
|
|
|
|
return m_seen;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
base::seen (bool _seen)
|
|
|
|
{
|
|
|
|
return m_seen = _seen;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-17 07:58:23 +11:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
base::fulfilled (void) const
|
|
|
|
{
|
|
|
|
if (!m_required ())
|
|
|
|
return true;
|
|
|
|
return seen ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-10 21:28:52 +10:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-06-30 22:06:10 +10:00
|
|
|
void
|
|
|
|
null::execute (void)
|
|
|
|
{
|
|
|
|
seen (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
null::execute (const char *restrict)
|
|
|
|
{
|
|
|
|
seen (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-11 13:16:20 +11:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
const std::string&
|
|
|
|
null::example (void) const
|
|
|
|
{
|
|
|
|
static const std::string EXAMPLE;
|
|
|
|
return EXAMPLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-30 22:07:02 +10:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2016-03-15 13:55:49 +11:00
|
|
|
present::present (bool &_data):
|
2015-06-30 22:07:02 +10:00
|
|
|
m_data (_data)
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
present::execute (void)
|
|
|
|
{
|
|
|
|
seen (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-11 13:16:20 +11:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
const std::string&
|
|
|
|
present::example (void) const
|
|
|
|
{
|
|
|
|
static const std::string EXAMPLE;
|
|
|
|
return EXAMPLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-30 22:07:02 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
present::finish (void)
|
|
|
|
{
|
|
|
|
m_data = seen ();
|
|
|
|
base::finish ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-30 22:06:10 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
2018-08-05 14:42:02 +10:00
|
|
|
namespace cruft::cmdopt::option {
|
2015-06-10 21:28:52 +10:00
|
|
|
template class value<uint16_t>;
|
|
|
|
template class value<uint32_t>;
|
|
|
|
template class value<uint64_t>;
|
2017-01-05 15:06:49 +11:00
|
|
|
}
|
2015-06-10 21:28:52 +10:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename T>
|
2016-03-15 13:55:49 +11:00
|
|
|
count<T>::count (T &_data):
|
|
|
|
value<T> (_data)
|
2015-06-15 17:47:18 +10:00
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
2015-06-10 21:28:52 +10:00
|
|
|
void
|
|
|
|
count<T>::execute (void)
|
|
|
|
{
|
2015-06-15 17:47:18 +10:00
|
|
|
++this->data ();
|
2015-06-30 22:04:54 +10:00
|
|
|
this->seen (true);
|
2015-06-10 21:28:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2018-08-05 14:42:02 +10:00
|
|
|
namespace cruft::cmdopt::option {
|
2015-06-10 21:28:52 +10:00
|
|
|
template class count<unsigned>;
|
2017-01-05 15:06:49 +11:00
|
|
|
}
|
2015-06-10 21:28:52 +10:00
|
|
|
|
|
|
|
|
2015-06-30 22:08:59 +10:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
static size_t
|
|
|
|
suffix_to_multiplier (char c)
|
|
|
|
{
|
|
|
|
switch (c) {
|
|
|
|
case 'e':
|
|
|
|
case 'E':
|
2018-08-05 14:42:02 +10:00
|
|
|
return cruft::pow (1024UL, 6u);
|
2015-06-30 22:08:59 +10:00
|
|
|
|
|
|
|
case 'p':
|
|
|
|
case 'P':
|
2018-08-05 14:42:02 +10:00
|
|
|
return cruft::pow (1024UL, 5u);
|
2015-06-30 22:08:59 +10:00
|
|
|
|
|
|
|
case 't':
|
|
|
|
case 'T':
|
2018-08-05 14:42:02 +10:00
|
|
|
return cruft::pow (1024UL, 4u);
|
2015-06-30 22:08:59 +10:00
|
|
|
|
|
|
|
case 'g':
|
|
|
|
case 'G':
|
2018-08-05 14:42:02 +10:00
|
|
|
return cruft::pow (1024UL, 3u);
|
2015-06-30 22:08:59 +10:00
|
|
|
|
|
|
|
case 'm':
|
|
|
|
case 'M':
|
2018-08-05 14:42:02 +10:00
|
|
|
return cruft::pow (1024UL, 2u);
|
2015-06-30 22:08:59 +10:00
|
|
|
|
|
|
|
case 'k':
|
|
|
|
case 'K':
|
2018-08-05 14:42:02 +10:00
|
|
|
return cruft::pow (1024UL, 1u);
|
2015-06-30 22:08:59 +10:00
|
|
|
|
|
|
|
default:
|
2016-03-15 13:55:49 +11:00
|
|
|
const char str[2] = { c, '\0' };
|
|
|
|
throw std::invalid_argument (str);
|
2015-06-30 22:08:59 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-11 19:55:32 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
2015-06-30 22:08:59 +10:00
|
|
|
void
|
|
|
|
bytes::execute (const char *restrict str)
|
|
|
|
{
|
|
|
|
const char *tail;
|
|
|
|
const char *last = str + strlen (str);
|
|
|
|
unsigned long val = std::strtoul (const_cast<char *> (str), const_cast<char**> (&tail), 10);
|
|
|
|
|
|
|
|
CHECK_LE (tail, last);
|
|
|
|
|
|
|
|
if (tail == str) {
|
2016-03-15 13:55:49 +11:00
|
|
|
throw invalid_value (str);
|
2015-06-30 22:08:59 +10:00
|
|
|
} else if (tail == last) {
|
|
|
|
data (val);
|
|
|
|
} else if (tail + 1 == last) {
|
2016-03-15 13:55:49 +11:00
|
|
|
try {
|
|
|
|
data (val * suffix_to_multiplier (*tail));
|
|
|
|
} catch (const std::invalid_argument&)
|
|
|
|
{ throw invalid_value (str); }
|
2015-06-30 22:08:59 +10:00
|
|
|
} else
|
2016-03-15 13:55:49 +11:00
|
|
|
throw invalid_value (str);
|
2015-06-30 22:08:59 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-10 21:28:52 +10:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int
|
2018-07-17 16:02:04 +10:00
|
|
|
parser::scan (int argc, char const *const *argv)
|
2015-06-10 21:28:52 +10:00
|
|
|
{
|
2018-07-17 16:02:04 +10:00
|
|
|
CHECK_GT (argc, 0);
|
|
|
|
CHECK (argv);
|
2015-06-10 21:28:52 +10:00
|
|
|
|
2015-06-30 22:04:54 +10:00
|
|
|
for (auto &j: m_options)
|
2018-07-17 16:02:04 +10:00
|
|
|
j.handler->start ();
|
2015-06-30 22:04:54 +10:00
|
|
|
|
2015-06-10 21:28:52 +10:00
|
|
|
// start iterating after our program's name
|
|
|
|
int i = 1;
|
|
|
|
while (i < argc) {
|
2018-07-17 16:02:04 +10:00
|
|
|
auto arg = argv[i];
|
|
|
|
auto len = strlen (arg);
|
2015-06-10 21:28:52 +10:00
|
|
|
|
|
|
|
// bail if there's no potential for an option
|
2018-07-17 16:02:04 +10:00
|
|
|
if (len < 2 || arg[0] != '-')
|
2016-03-15 13:55:49 +11:00
|
|
|
break;
|
|
|
|
|
|
|
|
// stop processing named options on '--'
|
2018-07-17 16:02:04 +10:00
|
|
|
if (len == 2 && arg[1] == '-') {
|
2016-03-15 13:55:49 +11:00
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
}
|
2015-06-10 21:28:52 +10:00
|
|
|
|
|
|
|
// parse longopt
|
2018-07-17 16:02:04 +10:00
|
|
|
auto inc = arg[1] == '-'
|
2015-06-10 21:28:52 +10:00
|
|
|
? parse_long (i, argc, argv)
|
|
|
|
: parse_short (i, argc, argv);
|
2015-07-21 03:17:04 +10:00
|
|
|
|
2015-06-10 21:28:52 +10:00
|
|
|
CHECK_GT (inc, 0);
|
|
|
|
i += inc;
|
|
|
|
}
|
|
|
|
|
2016-03-15 13:55:49 +11:00
|
|
|
// process the positional arguments
|
|
|
|
for (size_t cursor = 0; i < argc && cursor < m_positional.size (); ++i, ++cursor)
|
|
|
|
m_positional[cursor].get ().execute (argv[i]);
|
|
|
|
|
|
|
|
// ensure we've processed all the arguments
|
|
|
|
if (i != argc)
|
|
|
|
throw unhandled_argument (i);
|
|
|
|
|
|
|
|
// allow arguments to check if they've been successfully handled
|
2015-06-30 22:04:54 +10:00
|
|
|
for (auto &j: m_options)
|
2018-07-17 16:02:04 +10:00
|
|
|
j.handler->finish ();
|
2015-06-30 22:04:54 +10:00
|
|
|
|
2015-06-10 21:28:52 +10:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
int
|
2015-06-30 22:07:34 +10:00
|
|
|
parser::parse_long (int pos, int argc, const char *const *argv)
|
2015-06-10 21:28:52 +10:00
|
|
|
{
|
|
|
|
CHECK_LT (pos, argc);
|
|
|
|
CHECK_GE (pos, 0);
|
|
|
|
CHECK_GE (argc, 0);
|
|
|
|
CHECK (argv);
|
|
|
|
|
|
|
|
CHECK_EQ (argv[pos][0], '-');
|
|
|
|
CHECK_EQ (argv[pos][1], '-');
|
|
|
|
|
|
|
|
// break first atom into components and extract the key
|
|
|
|
const char *start = argv[pos] + 2;
|
|
|
|
const char *eq = strchr (start, '=');
|
|
|
|
const char *last = start + strlen (start);
|
|
|
|
|
|
|
|
std::string key { start, eq ? eq : last };
|
2015-09-11 19:55:32 +10:00
|
|
|
if (key == "help")
|
|
|
|
print_help (argc, argv);
|
2015-06-10 21:28:52 +10:00
|
|
|
|
2018-07-17 16:02:04 +10:00
|
|
|
auto &handler = m_long.at (key).get ();
|
2015-06-10 21:28:52 +10:00
|
|
|
|
|
|
|
// maybe grab a value from the next atom and dispatch
|
|
|
|
if (!eq) {
|
|
|
|
// check the next atom for the value
|
|
|
|
if (pos + 1 < argc)
|
|
|
|
if (argv[pos + 1][0] != '-') {
|
|
|
|
handler.execute (argv[pos+1]);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
handler.execute ();
|
|
|
|
} else {
|
|
|
|
handler.execute (eq+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
int
|
2015-06-30 22:07:34 +10:00
|
|
|
parser::parse_short (int pos, int argc, const char *const *argv)
|
2015-06-10 21:28:52 +10:00
|
|
|
{
|
|
|
|
CHECK_LT (pos, argc);
|
|
|
|
CHECK_GE (pos, 0);
|
|
|
|
CHECK_GE (argc, 0);
|
|
|
|
CHECK (argv);
|
|
|
|
|
|
|
|
CHECK_EQ (argv[pos][0], '-');
|
|
|
|
CHECK_NEQ (argv[pos][1], '-');
|
|
|
|
|
|
|
|
// we have a run of no-value keys
|
|
|
|
auto len = strlen (argv[pos]);
|
|
|
|
if (len > 2 || pos + 1 == argc || argv[pos+1][0] == '-') {
|
|
|
|
for (size_t i = 1; i < len; ++i) {
|
|
|
|
auto letter = argv[pos][i];
|
2015-09-11 19:55:32 +10:00
|
|
|
if (letter == 'h')
|
|
|
|
print_help (argc, argv);
|
2015-06-10 21:28:52 +10:00
|
|
|
|
2018-07-17 16:02:04 +10:00
|
|
|
m_short.at(letter).get ().execute ();
|
2015-06-10 21:28:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we have a value following
|
|
|
|
auto letter = argv[pos][1];
|
2018-07-17 16:02:04 +10:00
|
|
|
m_short.at (letter).get ().execute (argv[pos + 1]);
|
2015-06-10 21:28:52 +10:00
|
|
|
return 2;
|
|
|
|
}
|
2015-09-11 19:55:32 +10:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
void
|
|
|
|
parser::print_help (const int argc,
|
|
|
|
const char *const *argv) const
|
|
|
|
{
|
|
|
|
(void)argc;
|
|
|
|
|
|
|
|
CHECK_EQ (m_short.size (), m_options.size ());
|
|
|
|
CHECK_EQ (m_long.size (), m_options.size ());
|
|
|
|
|
|
|
|
if (m_options.empty ())
|
|
|
|
exit (0);
|
|
|
|
|
|
|
|
// find the longest long form argument so we can set field alignment
|
2016-03-11 13:16:20 +11:00
|
|
|
auto largestwidth = std::max_element (
|
|
|
|
m_long.begin (),
|
|
|
|
m_long.end (),
|
|
|
|
[] (const auto &a, const auto &b)
|
|
|
|
{
|
2018-07-17 16:02:04 +10:00
|
|
|
auto const &[a_key,a_obj] = a;
|
|
|
|
auto const &[b_key,b_obj] = b;
|
|
|
|
|
|
|
|
return a_key.size () < b_key.size ();
|
2015-09-11 19:55:32 +10:00
|
|
|
});
|
2018-07-17 16:02:04 +10:00
|
|
|
|
|
|
|
auto longwidth = largestwidth->first.size ();
|
2016-03-11 13:16:20 +11:00
|
|
|
|
|
|
|
// find the longest example text
|
|
|
|
auto largestexample = std::max_element (
|
|
|
|
m_options.cbegin (),
|
|
|
|
m_options.cend (),
|
|
|
|
[] (const auto &a, const auto &b)
|
|
|
|
{
|
2018-07-17 16:02:04 +10:00
|
|
|
return a.handler->example ().size () > b.handler->example ().size ();
|
2016-03-11 13:16:20 +11:00
|
|
|
});
|
|
|
|
|
2018-07-17 16:02:04 +10:00
|
|
|
auto longexample = largestexample->handler->example ().size ();
|
2015-09-11 19:55:32 +10:00
|
|
|
|
|
|
|
// field width requires an alignment. we don't care about preserving
|
|
|
|
// state as we're about to bail anyway
|
|
|
|
std::cout << std::left;
|
|
|
|
|
|
|
|
// print all the option info
|
|
|
|
std::cout << "usage: " << argv[0] << '\n';
|
|
|
|
|
2018-07-17 16:02:04 +10:00
|
|
|
for (auto &opt: m_options) {
|
2016-03-15 13:55:49 +11:00
|
|
|
auto s = std::find_if (
|
|
|
|
std::cbegin (m_short),
|
|
|
|
std::cend (m_short),
|
2018-07-17 16:02:04 +10:00
|
|
|
[&] (auto j) { return &j.second.get () == opt.handler.get (); }
|
2016-03-15 13:55:49 +11:00
|
|
|
);
|
|
|
|
|
|
|
|
auto l = std::find_if (
|
|
|
|
std::cbegin (m_long),
|
|
|
|
std::cend (m_long),
|
2018-07-17 16:02:04 +10:00
|
|
|
[&] (auto j) { return &j.second.get () == opt.handler.get (); }
|
2016-03-15 13:55:49 +11:00
|
|
|
);
|
|
|
|
|
|
|
|
std::cout << '\t';
|
|
|
|
if (s != std::cend (m_short))
|
2018-07-17 16:02:04 +10:00
|
|
|
std::cout << '-' << s->first << '\t';
|
2016-03-15 13:55:49 +11:00
|
|
|
else
|
|
|
|
std::cout << '\t';
|
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
std::cout << std::setw (cruft::cast::lossless<int> (longwidth));
|
2016-03-15 13:55:49 +11:00
|
|
|
if (l != std::cend (m_long))
|
2018-07-17 16:02:04 +10:00
|
|
|
std::cout << l->first << '\t';
|
2016-03-15 13:55:49 +11:00
|
|
|
else
|
|
|
|
std::cout << ' ' << '\t';
|
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
std::cout << std::setw (cruft::cast::lossless<int> (longexample)) << opt.handler->example () << '\t'
|
2018-07-17 16:02:04 +10:00
|
|
|
<< std::setw (0) << opt.description
|
2015-09-11 19:55:32 +10:00
|
|
|
<< '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
exit (0);
|
|
|
|
}
|
2016-03-15 13:55:49 +11:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
invalid_key::invalid_key (std::string _key):
|
|
|
|
m_key (std::move (_key))
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
const char*
|
|
|
|
invalid_key::what (void) const noexcept
|
|
|
|
{
|
|
|
|
return m_key.c_str ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
invalid_value::invalid_value (std::string _value):
|
2018-07-24 15:47:21 +10:00
|
|
|
m_value (std::move (_value))
|
2016-03-15 13:55:49 +11:00
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
const char*
|
|
|
|
invalid_value::what (void) const noexcept
|
|
|
|
{
|
|
|
|
return m_value.c_str ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
const char*
|
|
|
|
invalid_null::what (void) const noexcept
|
|
|
|
{
|
|
|
|
static const char WHAT[] = "unexpected null option was encountered";
|
|
|
|
return WHAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
const char*
|
|
|
|
invalid_required::what (void) const noexcept
|
|
|
|
{
|
|
|
|
static const char WHAT[] = "required option not seen";
|
|
|
|
return WHAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
unhandled_argument::unhandled_argument (int _index):
|
|
|
|
m_index (_index)
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
int
|
|
|
|
unhandled_argument::index (void) const noexcept
|
|
|
|
{
|
|
|
|
return m_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
const char*
|
|
|
|
unhandled_argument::what (void) const noexcept
|
|
|
|
{
|
|
|
|
static const char WHAT[] = "unhandled argument";
|
|
|
|
return WHAT;
|
|
|
|
}
|