bool CommandObject::ParseOptions ( Args& args, CommandReturnObject &result ) { // See if the subclass has options? Options *options = GetOptions(); if (options != NULL) { Error error; options->NotifyOptionParsingStarting(); // ParseOptions calls getopt_long, which always skips the zero'th item in the array and starts at position 1, // so we need to push a dummy value into position zero. args.Unshift("dummy_string"); error = args.ParseOptions (*options); // The "dummy_string" will have already been removed by ParseOptions, // so no need to remove it. if (error.Success()) error = options->NotifyOptionParsingFinished(); if (error.Success()) { if (options->VerifyOptions (result)) return true; } else { const char *error_cstr = error.AsCString(); if (error_cstr) { // We got an error string, lets use that result.AppendError(error_cstr); } else { // No error string, output the usage information into result options->GenerateOptionUsage (result.GetErrorStream(), this); } } result.SetStatus (eReturnStatusFailed); return false; } return true; }
static bool ProcessAliasOptionsArgs(lldb::CommandObjectSP &cmd_obj_sp, const char *options_args, OptionArgVectorSP &option_arg_vector_sp) { bool success = true; OptionArgVector *option_arg_vector = option_arg_vector_sp.get(); if (!options_args || (strlen(options_args) < 1)) return true; std::string options_string(options_args); Args args(options_args); CommandReturnObject result; // Check to see if the command being aliased can take any command options. Options *options = cmd_obj_sp->GetOptions(); if (options) { // See if any options were specified as part of the alias; if so, handle // them appropriately. ExecutionContext exe_ctx = cmd_obj_sp->GetCommandInterpreter().GetExecutionContext(); options->NotifyOptionParsingStarting(&exe_ctx); args.Unshift("dummy_arg"); args.ParseAliasOptions(*options, result, option_arg_vector, options_string); args.Shift(); if (result.Succeeded()) options->VerifyPartialOptions(result); if (!result.Succeeded() && result.GetStatus() != lldb::eReturnStatusStarted) { result.AppendError("Unable to create requested alias.\n"); return false; } } if (!options_string.empty()) { if (cmd_obj_sp->WantsRawCommandString()) option_arg_vector->push_back( OptionArgPair("<argument>", OptionArgValue(-1, options_string))); else { const size_t argc = args.GetArgumentCount(); for (size_t i = 0; i < argc; ++i) if (strcmp(args.GetArgumentAtIndex(i), "") != 0) option_arg_vector->push_back(OptionArgPair( "<argument>", OptionArgValue(-1, std::string(args.GetArgumentAtIndex(i))))); } } return success; }