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

Method Run

library/cpp/getopt/small/modchooser.cpp:180–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

178}
179
180int TModChooser::Run(const int argc, const char** argv) const {
181 Y_ENSURE(argc, "Can't run TModChooser with empty list of arguments.");
182
183 bool shiftArgs = true;
184 TString modeName;
185 if (argc == 1) {
186 if (DefaultMode.empty()) {
187 PrintHelp(argv[0], HelpAlwaysToStdErr);
188 return 0;
189 } else {
190 modeName = DefaultMode;
191 shiftArgs = false;
192 }
193 } else {
194 modeName = argv[1];
195 }
196
197 if (modeName == "-h" || modeName == "--help" || modeName == "-?") {
198 PrintHelp(argv[0], HelpAlwaysToStdErr);
199 return 0;
200 }
201 if (VersionHandler && (modeName == "-v" || modeName == "--version")) {
202 VersionHandler();
203 return 0;
204 }
205 if (!SvnRevisionOptionDisabled && modeName == "--svnrevision") {
206 NLastGetopt::PrintVersionAndExit(nullptr);
207 }
208
209 auto modeIter = Modes.find(modeName);
210 if (modeIter == Modes.end() && !DefaultMode.empty()) {
211 modeIter = Modes.find(DefaultMode);
212 shiftArgs = false;
213 }
214
215 if (modeIter == Modes.end()) {
216 Cerr << "Unknown mode " << modeName.Quote() << "." << Endl;
217 PrintHelp(argv[0], true);
218 return 1;
219 }
220
221 TVector<TString> subcommandPath = SubcommandPath_;
222 subcommandPath.push_back(modeIter->second->Name);
223 modeIter->second->Main->SetSubcommandPath(std::move(subcommandPath));
224
225 if (shiftArgs) {
226 TString firstArg;
227 TVector<const char*> nargv(Reserve(argc));
228
229 if (PrintShortCommandInUsage) {
230 firstArg = modeIter->second->Name;
231 } else {
232 firstArg = argv[0] + TString(" ") + modeIter->second->Name;
233 }
234
235 nargv.push_back(firstArg.data());
236
237 for (int i = 2; i < argc; ++i) {

Callers 2

mainFunction · 0.45
Y_UNIT_TESTFunction · 0.45

Calls 15

PrintHelpFunction · 0.85
PrintVersionAndExitFunction · 0.85
ReserveFunction · 0.85
GetOptionsFunction · 0.85
DoRunFunction · 0.85
SetSubcommandPathMethod · 0.80
moveFunction · 0.50
RunFunction · 0.50
emptyMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected