2015-06-10 21:28:52 +10:00
|
|
|
/*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
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"
|
|
|
|
#include "debug.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
|
|
|
|
2016-03-15 13:55:49 +11:00
|
|
|
using namespace util::cmdopt;
|
|
|
|
using namespace util::cmdopt::option;
|
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
|
|
|
{
|
|
|
|
if (m_required && !m_seen)
|
2016-03-15 13:55:49 +11:00
|
|
|
throw invalid_required ();
|
2015-09-11 19:55:32 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-30 22:04:54 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
base::required (void) const
|
|
|
|
{
|
|
|
|
return m_required;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
base::required (bool _required)
|
|
|
|
{
|
|
|
|
return m_required = _required;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
base::seen (void) const
|
|
|
|
{
|
|
|
|
return m_seen;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
base::seen (bool _seen)
|
|
|
|
{
|
|
|
|
return m_seen = _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
|
|
|
//-----------------------------------------------------------------------------
|
2017-01-05 15:06:49 +11:00
|
|
|
namespace util::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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-01-05 15:06:49 +11:00
|
|
|
namespace util::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':
|
2015-11-13 17:59:58 +11:00
|
|
|
return util::pow (1024UL, 6);
|
2015-06-30 22:08:59 +10:00
|
|
|
|
|
|
|
case 'p':
|
|
|
|
case 'P':
|
2015-11-13 17:59:58 +11:00
|
|
|
return util::pow (1024UL, 5);
|
2015-06-30 22:08:59 +10:00
|
|
|
|
|
|
|
case 't':
|
|
|
|
case 'T':
|
2015-11-13 17:59:58 +11:00
|
|
|
return util::pow (1024UL, 4);
|
2015-06-30 22:08:59 +10:00
|
|
|
|
|
|
|
case 'g':
|
|
|
|
case 'G':
|
2015-11-13 17:59:58 +11:00
|
|
|
return util::pow (1024UL, 3);
|
2015-06-30 22:08:59 +10:00
|
|
|
|
|
|
|
case 'm':
|
|
|
|
case 'M':
|
2015-11-13 17:59:58 +11:00
|
|
|
return util::pow (1024UL, 2);
|
2015-06-30 22:08:59 +10:00
|
|
|
|
|
|
|
case 'k':
|
|
|
|
case 'K':
|
2015-11-13 17:59:58 +11:00
|
|
|
return util::pow (1024UL, 1);
|
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
|
2015-06-30 22:07:34 +10:00
|
|
|
parser::scan (int argc, const char *const *argv)
|
2015-06-10 21:28:52 +10:00
|
|
|
{
|
|
|
|
CHECK_GE (argc, 0);
|
|
|
|
CHECK (argv);
|
|
|
|
|
2015-06-30 22:04:54 +10:00
|
|
|
for (auto &j: m_options)
|
2016-03-15 13:55:49 +11:00
|
|
|
std::get<std::unique_ptr<option::base>> (j)->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) {
|
|
|
|
auto len = strlen (argv[i]);
|
|
|
|
|
|
|
|
// bail if there's no potential for an option
|
|
|
|
if (len < 2 || argv[i][0] != '-')
|
2016-03-15 13:55:49 +11:00
|
|
|
break;
|
|
|
|
|
|
|
|
// stop processing named options on '--'
|
|
|
|
if (len == 2 && argv[i][1] == '-') {
|
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
}
|
2015-06-10 21:28:52 +10:00
|
|
|
|
|
|
|
// parse longopt
|
|
|
|
auto inc = argv[i][1] == '-'
|
|
|
|
? 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)
|
2016-03-15 13:55:49 +11:00
|
|
|
std::get<std::unique_ptr<option::base>> (j)->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
|
|
|
|
|
|
|
// find the handler
|
|
|
|
auto handle_pos = std::find_if (m_long.begin (),
|
|
|
|
m_long.end (),
|
2016-03-15 13:55:49 +11:00
|
|
|
[&] (auto i) { return std::get<std::string> (i) == key; });
|
2015-06-10 21:28:52 +10:00
|
|
|
if (handle_pos == m_long.end ())
|
|
|
|
throw invalid_key (key);
|
|
|
|
|
2016-03-15 13:55:49 +11:00
|
|
|
auto &handler = std::get<option::base&> (*handle_pos);
|
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
|
|
|
|
|
|
|
auto hpos = std::find_if (m_short.begin (),
|
|
|
|
m_short.end (),
|
2016-03-15 13:55:49 +11:00
|
|
|
[letter] (auto j) { return std::get<char> (j) == letter; });
|
2015-06-10 21:28:52 +10:00
|
|
|
if (hpos == m_short.end ())
|
2017-01-05 15:15:18 +11:00
|
|
|
throw invalid_key (std::string (1, letter));
|
2016-03-15 13:55:49 +11:00
|
|
|
std::get<option::base&> (*hpos).execute ();
|
2015-06-10 21:28:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we have a value following
|
|
|
|
auto letter = argv[pos][1];
|
|
|
|
auto hpos = std::find_if (m_short.begin (),
|
|
|
|
m_short.end (),
|
2016-03-15 13:55:49 +11:00
|
|
|
[letter] (auto i) { return std::get<char> (i) == letter; });
|
2015-06-10 21:28:52 +10:00
|
|
|
if (hpos == m_short.end ())
|
2017-01-05 15:15:18 +11:00
|
|
|
throw invalid_key (std::string (1, letter));
|
2016-03-15 13:55:49 +11:00
|
|
|
std::get<option::base&> (*hpos).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)
|
|
|
|
{
|
|
|
|
return std::get<std::string> (a).size () < std::get<std::string> (b).size ();
|
2015-09-11 19:55:32 +10:00
|
|
|
});
|
2016-05-12 17:39:33 +10:00
|
|
|
auto longwidth = std::get<std::string> (*largestwidth).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)
|
|
|
|
{
|
|
|
|
const auto &example_a = std::get<std::unique_ptr<option::base>> (a)->example ();
|
|
|
|
const auto &example_b = std::get<std::unique_ptr<option::base>> (b)->example ();
|
|
|
|
|
|
|
|
return example_a.size () > example_b.size ();
|
|
|
|
});
|
|
|
|
|
2016-05-12 17:39:33 +10:00
|
|
|
auto longexample = std::get<std::unique_ptr<option::base>> (*largestexample)->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';
|
|
|
|
|
|
|
|
for (auto &o: m_options) {
|
2016-03-15 13:55:49 +11:00
|
|
|
auto ptr = std::get<std::unique_ptr<option::base>> (o).get ();
|
|
|
|
|
|
|
|
auto s = std::find_if (
|
|
|
|
std::cbegin (m_short),
|
|
|
|
std::cend (m_short),
|
|
|
|
[ptr] (auto j) {
|
|
|
|
return &std::get<option::base&> (j) == ptr;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
auto l = std::find_if (
|
|
|
|
std::cbegin (m_long),
|
|
|
|
std::cend (m_long),
|
|
|
|
[ptr] (auto j) {
|
|
|
|
return &std::get<option::base&> (j) == ptr;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
std::cout << '\t';
|
|
|
|
if (s != std::cend (m_short))
|
|
|
|
std::cout << '-' << std::get<char> (*s) << '\t';
|
|
|
|
else
|
|
|
|
std::cout << '\t';
|
|
|
|
|
2016-05-12 17:39:33 +10:00
|
|
|
std::cout << std::setw (trunc_cast<int> (longwidth));
|
2016-03-15 13:55:49 +11:00
|
|
|
if (l != std::cend (m_long))
|
|
|
|
std::cout << std::get<std::string> (*l) << '\t';
|
|
|
|
else
|
|
|
|
std::cout << ' ' << '\t';
|
|
|
|
|
2016-05-12 17:39:33 +10:00
|
|
|
std::cout << std::setw (trunc_cast<int> (longexample)) << ptr->example () << '\t'
|
2016-03-15 13:55:49 +11:00
|
|
|
<< std::setw (0) << std::get<std::string> (o)
|
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):
|
|
|
|
m_value (_value)
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
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;
|
|
|
|
}
|