MCPcopy Create free account
hub / github.com/catboost/catboost / PrintUsage

Method PrintUsage

library/cpp/getopt/small/last_getopt_opts.cpp:364–485  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

362 }
363
364 void TOpts::PrintUsage(const TStringBuf& program, IOutputStream& osIn, const NColorizer::TColors& colors) const {
365 TStringStream os;
366
367 if (!Title.empty())
368 os << Title << "\n\n";
369
370 PrintCmdLine(program, os, colors);
371
372 TVector<TString> leftColumn(Opts_.size());
373 TVector<size_t> leftColumnSizes(leftColumn.size());
374 const size_t kMaxLeftWidth = 25;
375 size_t leftWidth = 0;
376 size_t requiredOptionsCount = 0;
377 NColorizer::TColors disabledColors(false);
378
379 for (size_t i = 0; i < Opts_.size(); i++) {
380 const TOpt* opt = Opts_[i].Get();
381 if (opt->IsHidden())
382 continue;
383 leftColumn[i] = FormatOption(opt, colors);
384 size_t leftColumnSize = leftColumn[i].size();
385 if (colors.IsTTY()) {
386 leftColumnSize -= NColorizer::TotalAnsiEscapeCodeLen(leftColumn[i]);
387 }
388 leftColumnSizes[i] = leftColumnSize;
389 if (leftColumnSize <= kMaxLeftWidth) {
390 leftWidth = Max(leftWidth, leftColumnSize);
391 }
392 if (opt->IsRequired())
393 requiredOptionsCount++;
394 }
395
396 const TString leftPadding(leftWidth, ' ');
397
398 for (size_t sectionId = 0; sectionId <= 1; sectionId++) {
399 bool requiredOptionsSection = (sectionId == 0);
400
401 if (requiredOptionsSection) {
402 if (requiredOptionsCount == 0)
403 continue;
404 os << Endl << colors.BoldColor() << "Required parameters" << colors.OldColor() << ":" << Endl;
405 } else {
406 if (requiredOptionsCount == Opts_.size())
407 continue;
408 if (requiredOptionsCount == 0)
409 os << Endl << colors.BoldColor() << "Options" << colors.OldColor() << ":" << Endl;
410 else
411 os << Endl << colors.BoldColor() << "Optional parameters" << colors.OldColor() << ":" << Endl; // optional options would be a tautology
412 }
413
414 for (size_t i = 0; i < Opts_.size(); i++) {
415 const TOpt* opt = Opts_[i].Get();
416
417 if (opt->IsHidden())
418 continue;
419 if (opt->IsRequired() != requiredOptionsSection)
420 continue;
421

Callers 5

DoRunMethod · 0.45
DummyHelpMethod · 0.45
PrintUsageAndExitFunction · 0.45
Y_UNIT_TESTFunction · 0.45
ParseMetadataFunction · 0.45

Calls 15

FormatOptionFunction · 0.85
QuoteForHelpFunction · 0.85
IsHiddenMethod · 0.80
IsTTYMethod · 0.80
BoldColorMethod · 0.80
OldColorMethod · 0.80
GetHelpMethod · 0.80
ChopMethod · 0.80
GetChoicesHelpMethod · 0.80
HasDefaultValueMethod · 0.80
CyanColorMethod · 0.80
WrapFunction · 0.70

Tested by

no test coverage detected