option *options::getopt_short(pstring arg) { for (auto & optbase : m_opts) { auto opt = dynamic_cast<option *>(optbase); if (opt && opt->short_opt() == arg) return opt; } return nullptr; }
void Command::dump_usage(std::ostream &out, bool show_hidden) const { std::stringstream ss; out << std::endl; ss << get_name() << " - "; dump_short_description(ss, show_hidden); indented_dump(ss.str(), out); out << std::endl << std::endl; ss.str(""); dump_section(out, "Synopsis", show_hidden); dump_synopsis(ss, show_hidden); indented_dump(ss.str(), out); out << std::endl; ss.str(""); dump_section(out, "Description", show_hidden); dump_full_description(ss, show_hidden); indented_dump(ss.str(), out); out << std::endl; ss.str(""); dump_output_section(ss, show_hidden); indented_dump(ss.str(), out); out << std::endl; dump_section(out, "Options", show_hidden); std::vector<std::string> str_opts; size_t max_width(0); for (CommandOptions::const_iterator it = _options.begin(); it != _options.end(); ++it) { if (show_hidden == false && it->second->is_hidden()) continue; std::stringstream ss; std::string short_opt("-"); short_opt.append(1, it->second->get_short_opt()); std::string long_opt("--"); long_opt.append(it->second->get_long_opt()); ss << " "; ss << Boldify(short_opt) << ", " << Boldify(long_opt); if (it->second->is_arg_expected()) ss << " " << it->second->get_arg_name(); str_opts.push_back(ss.str()); size_t real_size = Get_real_string_size(ss.str()); if (real_size > max_width) max_width = real_size; } size_t i(0); for (CommandOptions::const_iterator it = _options.begin(); it != _options.end(); ++it) { if (show_hidden == false && it->second->is_hidden()) continue; indented_dump(str_opts.at(i), out, 0, max_width + 2, true, true); std::stringstream ss; ss << it->second->get_description(); if (it->second->is_arg_expected() && it->second->is_mandatory() == false && it->second->get_default_value().empty() == false) ss << std::endl << "Default is '" << it->second->get_default_value() << "'."; indented_dump(ss.str(), out, max_width + 2, Get_tty_cols(), false, false); out << std::endl; ++i; } out << std::endl; dump_section(out, "Examples", show_hidden); ss.str(""); dump_examples(ss, show_hidden); indented_dump(ss.str(), out); out << std::endl; if (_see_also.empty() == false) { dump_section(out, "See also", show_hidden); ss.str(""); dump_see_also(ss, show_hidden); indented_dump(ss.str(), out); out << std::endl; out << std::endl; } dump_section(out, "Author", show_hidden); ss.str(""); ss << EXA_COPYRIGHT << std::endl; indented_dump(ss.str(), out); out << std::endl; }