1#ifndef GETOPT_WRAPPER_HPP
2#define GETOPT_WRAPPER_HPP
73 option_with_desc(
const char* _name,
int _has_arg,
int* _flag,
int _val,
const char* _description)
99 std::vector<option_with_desc>
opts_;
153 opts_(std::move(long_opts))
158 for (
auto it =
opts_.begin(); it !=
opts_.end(); ++it)
161 max_long_opt_length_ = std::max(max_long_opt_length_, it->name ? std::strlen(it->name) : 0);
164 short_opt_string_ += (char)it->val;
165 if (it->has_arg == required_argument)
166 short_opt_string_ +=
':';
204 for (
auto it =
opts_.begin(); it !=
opts_.end(); ++it)
206 if (!it->description)
209 if (std::isprint(it->val))
212 os <<
" -" << (char)it->val <<
", ";
214 os <<
" -" << (char)it->val <<
" ";
219 std::size_t n_spaces = 2;
221 os <<
"--" << it->name;
226 for (std::size_t i = 0; i < n_spaces; ++i)
228 os << it->description <<
'\n';
std::string short_opt_string_
Concatenated short option string.
Definition getopt_wrapper.hpp:116
getopt_wrapper(std::string usage_str, std::vector< option_with_desc > long_opts)
Constructs a getopt_wrapper object for parsing command-line options.
Definition getopt_wrapper.hpp:151
std::size_t max_long_opt_length_
Maximum long option length.
Definition getopt_wrapper.hpp:124
std::vector< option > long_options_
Storage of long options for getopt parsing.
Definition getopt_wrapper.hpp:90
void print_usage(std::ostream &os)
Prints the program usage and all available options to a stream.
Definition getopt_wrapper.hpp:200
std::string usage_str_
Program usage/help string.
Definition getopt_wrapper.hpp:107
std::vector< option_with_desc > opts_
Original option definitions with descriptions.
Definition getopt_wrapper.hpp:99
option_with_desc(const char *_name, int _has_arg, int *_flag, int _val, const char *_description)
Construct an option with description.
Definition getopt_wrapper.hpp:73
const char * description
Description of the command-line option for help output.
Definition getopt_wrapper.hpp:62