| 135 | } |
| 136 | |
| 137 | std::string common_arg::to_string() { |
| 138 | // params for printing to console |
| 139 | const static int n_leading_spaces = 40; |
| 140 | const static int n_char_per_line_help = 70; // TODO: detect this based on current console |
| 141 | std::string leading_spaces(n_leading_spaces, ' '); |
| 142 | |
| 143 | std::ostringstream ss; |
| 144 | for (const auto arg : args) { |
| 145 | if (arg == args.front()) { |
| 146 | if (args.size() == 1) { |
| 147 | ss << arg; |
| 148 | } else { |
| 149 | // first arg is usually abbreviation, we need padding to make it more beautiful |
| 150 | auto tmp = std::string(arg) + ", "; |
| 151 | auto spaces = std::string(std::max(0, 7 - (int)tmp.size()), ' '); |
| 152 | ss << tmp << spaces; |
| 153 | } |
| 154 | } else { |
| 155 | ss << arg << (arg != args.back() ? ", " : ""); |
| 156 | } |
| 157 | } |
| 158 | if (value_hint) ss << " " << value_hint; |
| 159 | if (value_hint_2) ss << " " << value_hint_2; |
| 160 | if (ss.tellp() > n_leading_spaces - 3) { |
| 161 | // current line is too long, add new line |
| 162 | ss << "\n" << leading_spaces; |
| 163 | } else { |
| 164 | // padding between arg and help, same line |
| 165 | ss << std::string(leading_spaces.size() - ss.tellp(), ' '); |
| 166 | } |
| 167 | const auto help_lines = break_str_into_lines(help, n_char_per_line_help); |
| 168 | for (const auto & line : help_lines) { |
| 169 | ss << (&line == &help_lines.front() ? "" : leading_spaces) << line << "\n"; |
| 170 | } |
| 171 | return ss.str(); |
| 172 | } |
| 173 | |
| 174 | // |
| 175 | // downloader |
no test coverage detected