libcruft-util/cmdopt2/args.cpp

129 lines
2.6 KiB
C++

#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;
}
//-----------------------------------------------------------------------------
positional_t
positional_t::ignore (void) const
{
positional_t res = *this;
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;
}
//-----------------------------------------------------------------------------
keyword_t
keyword_t::acceptor (acceptor0_t _acceptor)
{
keyword_t res = *this;
res.acceptor0 = _acceptor;
return res;
}
//-----------------------------------------------------------------------------
keyword_t
keyword_t::ignore (void) const
{
keyword_t res = *this;
res.acceptor0.reset ();
res.acceptor1.reset ();
return res;
}