21 out << m_cmd.description() <<
'\n'
26 if (!m_cmd.path().empty()) {
27 out << m_cmd.path() <<
' ';
31 const auto& options = m_cmd.options();
32 const auto& args = m_cmd.arguments();
33 const auto& cmds = m_cmd.commands();
35 if (!options.empty()) {
40 out <<
" <ARGUMENTS>";
49 print_arguments(out, args);
50 print_options(out, options);
51 print_commands(out, cmds);
60 std::size_t max_size = 0;
62 for (
const auto& arg : args) {
63 max_size = std::max(max_size, arg.name().size() + 2);
66 out <<
"Arguments:\n";
68 for (
const auto& arg : args) {
69 print_item(out, max_size,
"", arg.name(), arg.description());
75 if (options.empty()) {
79 std::size_t max_size = 0;
81 for (
const auto& opt : options) {
84 if (opt.long_name() && opt.short_name()) {
89 if (opt.short_name()) {
94 if (opt.long_name()) {
96 size += 2 + opt.long_name()->size();
99 if (opt.has_value()) {
101 size += 3 + opt.value_name().size();
104 max_size = std::max(max_size, size);
108 for (
const auto& opt : options) {
111 bool has_short_name = opt.short_name().has_value();
113 if (has_short_name) {
115 name += *opt.short_name();
118 if (opt.long_name()) {
119 if (has_short_name) {
124 name += *opt.long_name();
127 if (opt.has_value()) {
129 name += opt.value_name();
133 std::string_view prefix;
134 if (opt.required()) {
135 prefix =
"(required) ";
138 print_item(out, max_size, prefix, name, opt.description());
148 std::size_t max_size = 0;
150 for (
const auto& cmd : cmds) {
151 max_size = std::max(max_size, cmd.name().size());
154 out <<
"Commands:\n";
156 for (
const auto& cmd : cmds) {
157 print_item(out, max_size,
"", cmd.name(), cmd.description());
164 std::size_t max_size,
165 std::string_view prefix,
166 std::string_view name,
167 std::string_view description
169 const std::size_t indent = 2;
170 const std::size_t name_width = indent + max_size;
171 const std::size_t desc_start = name_width + indent;
173 out <<
" " << std::left << std::setw(name_width) << name;
174 const std::size_t available_width = m_term_size - desc_start;
176 if (description.size() + prefix.size() <= available_width) {
177 out << prefix << description <<
'\n';
181 std::string desc(prefix);
184 std::istringstream stream(desc);
187 std::size_t line_len = 0;
188 bool first_line =
true;
190 while (stream >> word) {
191 if (!first_line && line_len + word.size() + 1 > available_width) {
192 out <<
'\n' << std::setw(desc_start) <<
"";
202 line_len += word.size();
void print_item(std::ostream &out, std::size_t max_size, std::string_view prefix, std::string_view name, std::string_view description)
Definition help_impl.h:162