24 #ifndef CLIOPTION20140107H
25 #define CLIOPTION20140107H
45 Option(
char shortname,
const char* longname,
int has_argument, std::string description)
46 : description_(std::move(description))
48 c_opt_.name = longname;
50 c_opt_.has_arg = has_argument;
51 c_opt_.flag =
nullptr;
52 c_opt_.val = shortname;
56 option
c_opt()
const {
return c_opt_; }
65 opt_code += std::string(1, c_opt_.val);
66 if (c_opt_.has_arg == no_argument)
68 else if (c_opt_.has_arg == required_argument)
70 else if (c_opt_.has_arg == optional_argument)
79 std::stringstream
usage;
81 usage <<
"-" << (char)c_opt_.val <<
", ";
82 usage <<
"--" << c_opt_.name;
83 usage << std::string(std::max(1, (
int)(20 -
usage.str().size())),
' ') << description_;
88 static void convert_vector(
const std::vector<Option>& options, std::vector<option>* c_options,
89 std::string* opt_string)
91 for (
const auto& option : options)
93 c_options->push_back(option.c_opt());
94 *opt_string += option.opt_code();
96 option zero = {
nullptr, 0,
nullptr, 0};
97 c_options->push_back(zero);
102 std::string description_;