| 334 | } |
| 335 | |
| 336 | void TOptsParser::Finish() { |
| 337 | const TOpts::TOptsVector& optvec = Opts_->Opts_; |
| 338 | if (optvec.size() == OptsSeen_.size()) |
| 339 | return; |
| 340 | |
| 341 | TVector<TString> missingLong; |
| 342 | TVector<char> missingShort; |
| 343 | |
| 344 | TOpts::TOptsVector::const_iterator it; |
| 345 | for (it = optvec.begin(); it != optvec.end(); ++it) { |
| 346 | const TOpt* opt = (*it).Get(); |
| 347 | if (nullptr == opt) |
| 348 | continue; |
| 349 | if (OptsSeen_.contains(opt)) |
| 350 | continue; |
| 351 | |
| 352 | if (opt->IsRequired()) { |
| 353 | const TOpt::TLongNames& optnames = opt->GetLongNames(); |
| 354 | if (!optnames.empty()) |
| 355 | missingLong.push_back(optnames[0]); |
| 356 | else { |
| 357 | const char ch = opt->GetCharOr0(); |
| 358 | if (0 != ch) |
| 359 | missingShort.push_back(ch); |
| 360 | } |
| 361 | continue; |
| 362 | } |
| 363 | |
| 364 | if (opt->HasDefaultValue()) |
| 365 | OptsDefault_.push_back(opt); |
| 366 | } |
| 367 | |
| 368 | // also indicates subsequent options, if any, haven't been seen actually |
| 369 | OptsSeen_.clear(); |
| 370 | |
| 371 | const size_t nmissing = missingLong.size() + missingShort.size(); |
| 372 | if (0 == nmissing) |
| 373 | return; |
| 374 | |
| 375 | TUsageException usage; |
| 376 | usage << "The following option"; |
| 377 | usage << ((1 == nmissing) ? " is" : "s are"); |
| 378 | usage << " required:"; |
| 379 | for (size_t i = 0; i != missingLong.size(); ++i) |
| 380 | usage << " --" << missingLong[i]; |
| 381 | for (size_t i = 0; i != missingShort.size(); ++i) |
| 382 | usage << " -" << missingShort[i]; |
| 383 | throw usage; // don't need lineinfo, just the message |
| 384 | } |
| 385 | |
| 386 | void TOptsParser::PrintUsage(IOutputStream& os, const NColorizer::TColors& colors) const { |
| 387 | Opts_->PrintUsage(ProgramName(), os, colors); |
nothing calls this directly
no test coverage detected