| 275 | } |
| 276 | |
| 277 | static TString FormatOption(const TOpt* option, const NColorizer::TColors& colors) { |
| 278 | TStringStream result; |
| 279 | const TOpt::TShortNames& shorts = option->GetShortNames(); |
| 280 | const TOpt::TLongNames& longs = option->GetLongNames(); |
| 281 | |
| 282 | const size_t nopts = shorts.size() + longs.size(); |
| 283 | const bool multiple = 1 < nopts; |
| 284 | if (multiple) |
| 285 | result << '{'; |
| 286 | for (size_t i = 0; i < nopts; ++i) { |
| 287 | if (multiple && 0 != i) |
| 288 | result << '|'; |
| 289 | |
| 290 | if (i < shorts.size()) // short |
| 291 | result << colors.GreenColor() << '-' << shorts[i] << colors.OldColor(); |
| 292 | else |
| 293 | result << colors.GreenColor() << "--" << longs[i - shorts.size()] << colors.OldColor(); |
| 294 | } |
| 295 | if (multiple) |
| 296 | result << '}'; |
| 297 | |
| 298 | static const TString metavarDef("VAL"); |
| 299 | const TString& title = option->GetArgTitle(); |
| 300 | const TString& metavar = title.empty() ? metavarDef : title; |
| 301 | |
| 302 | if (option->GetHasArg() == OPTIONAL_ARGUMENT) { |
| 303 | if (option->IsEqParseOnly()) { |
| 304 | result << "[="; |
| 305 | } else { |
| 306 | result << " ["; |
| 307 | } |
| 308 | result << metavar; |
| 309 | if (option->HasOptionalValue()) |
| 310 | result << ':' << option->GetOptionalValue(); |
| 311 | result << ']'; |
| 312 | } else if (option->GetHasArg() == REQUIRED_ARGUMENT) { |
| 313 | if (option->IsEqParseOnly()) { |
| 314 | result << "="; |
| 315 | } else { |
| 316 | result << " "; |
| 317 | } |
| 318 | result << metavar; |
| 319 | } else |
| 320 | Y_ASSERT(option->GetHasArg() == NO_ARGUMENT); |
| 321 | |
| 322 | return result.Str(); |
| 323 | } |
| 324 | |
| 325 | void TOpts::PrintCmdLine(const TStringBuf& program, IOutputStream& os, const NColorizer::TColors& colors) const { |
| 326 | os << colors.BoldColor() << "Usage" << colors.OldColor() << ": "; |
no test coverage detected