libcruft-util/cruft/util/cmdopt2/args.cpp

129 lines
2.6 KiB
C++
Raw Normal View History

2022-03-18 13:26:10 +11:00
#include "./args.hpp"
using cruft::cmdopt2::positional_t;
using cruft::cmdopt2::keyword_t;
///////////////////////////////////////////////////////////////////////////////
positional_t
cruft::cmdopt2::positional (char const *name)
{
return positional (std::string (name));
}
//-----------------------------------------------------------------------------
positional_t
cruft::cmdopt2::positional (std::string &&name)
{
positional_t res {};
res.name = name;
return res;
}
2022-03-18 16:03:43 +11:00
//-----------------------------------------------------------------------------
positional_t
positional_t::ignore (void) const
2022-03-18 16:03:43 +11:00
{
positional_t res = *this;
2022-03-18 16:03:43 +11:00
res.acceptor1.reset ();
return res;
}
///////////////////////////////////////////////////////////////////////////////
keyword_t
cruft::cmdopt2::keyword (char const *name)
{
return keyword (std::string (name));
}
//-----------------------------------------------------------------------------
keyword_t
cruft::cmdopt2::keyword (std::string &&name)
{
keyword_t res {};
res.name = name;
res.long_ = name;
return res;
}
//-----------------------------------------------------------------------------
keyword_t
keyword_t::flag (void) const
{
keyword_t res = *this;
res.long_.reset ();
res.short_.reset ();
return res;
}
//-----------------------------------------------------------------------------
keyword_t
keyword_t::flag (char val) const
{
keyword_t res = *this;
res.short_ = val;
return res;
}
//-----------------------------------------------------------------------------
keyword_t
keyword_t::flag (std::string_view val) const
{
keyword_t res = *this;
res.long_ = val;
return res;
}
//-----------------------------------------------------------------------------
keyword_t
keyword_t::count (int &val) const
{
CHECK (!acceptor1 and !acceptor0);
keyword_t res = *this;
res.acceptor0 = [&val] (void) { ++val; };
return res;
}
//-----------------------------------------------------------------------------
keyword_t
keyword_t::present (bool &val) const
{
CHECK (!acceptor1 and !acceptor0);
val = false;
keyword_t res = *this;
res.acceptor0 = [&val] (void) { val = true; };
return res;
2022-03-18 14:02:56 +11:00
}
//-----------------------------------------------------------------------------
keyword_t
keyword_t::acceptor (acceptor0_t _acceptor)
2022-03-18 14:02:56 +11:00
{
keyword_t res = *this;
2022-03-18 14:02:56 +11:00
res.acceptor0 = _acceptor;
return res;
2022-03-18 16:03:43 +11:00
}
//-----------------------------------------------------------------------------
keyword_t
keyword_t::ignore (void) const
2022-03-18 16:03:43 +11:00
{
keyword_t res = *this;
2022-03-18 16:03:43 +11:00
res.acceptor0.reset ();
res.acceptor1.reset ();
return res;
}