46 using OPTEL = std::map<const char, const std::pair<const std::string, const std::string>>;
58 UsageMan(
const std::string& prognm,
const std::string& argstr,
const std::string& params,
59 int splen=3,
int argoptlen=23)
60 : prognm_(prognm), params_(params), argstr_(argstr), splen_(splen), argoptlen_(argoptlen)
62 std::sort(argstr_.begin(), argstr_.end());
73 bool add(
const char sw,
const std::string& lsw,
const std::string& help)
75 return optels_.insert({sw, std::pair<const std::string, const std::string>(lsw, help)}).second;
80 void add(
const std::string& xtr)
82 std::string topush(xtr);
83 std::string::size_type spos;
84 while ((spos = topush.find_first_of(
'@')) != std::string::npos)
85 topush.replace(spos, 1, std::string(splen_,
' '));
86 xtrlines_.push_back(topush);
91 void setdesc(
const std::string& desc) { description_ = desc; }
95 void print(std::ostream& os)
const
97 if (!description_.empty())
98 os << description_ << std::endl << std::endl;
99 os <<
"Usage: " << prognm_ <<
" [-";
100 for (std::string::const_iterator itr(argstr_.begin()); itr != argstr_.end(); ++itr)
103 os <<
"] " << params_ << std::endl;
104 const std::string
spacer(splen_,
' ');
105 for (OPTEL::const_iterator itr(optels_.begin()); itr != optels_.end(); ++itr)
107 std::ostringstream ostr;
108 ostr <<
'-' << itr->first <<
",--" << itr->second.first;
109 os << spacer << std::left << std::setw(argoptlen_) << ostr.str()
110 <<
' ' << itr->second.second << std::endl;
112 for (std::list<std::string>::const_iterator itr(xtrlines_.begin()); itr != xtrlines_.end(); ++itr)
113 os << *itr << std::endl;
117 #endif // _USAGE_HPP_
UsageMan(const std::string &prognm, const std::string &argstr, const std::string ¶ms, int splen=3, int argoptlen=23)
bool add(const char sw, const std::string &lsw, const std::string &help)
void add(const std::string &xtr)
std::list< std::string > xtrlines_
const std::string prognm_
void setdesc(const std::string &desc)
void print(std::ostream &os) const
const std::string params_
Convenient program help/usage wrapper. Generates a standardised usage message.
std::map< const char, const std::pair< const std::string, const std::string >> OPTEL