MCPcopy Create free account
hub / github.com/apache/trafficserver / parse

Method parse

src/tscore/ArgParser.cc:149–197  ·  view source on GitHub ↗

Top level call of parsing

Source from the content-addressed store, hash-verified

147
148// Top level call of parsing
149Arguments
150ArgParser::parse(const char **argv)
151{
152 // deal with argv first
153 int size = 0;
154 _argv.clear();
155 while (argv[size]) {
156 _argv.push_back(argv[size]);
157 size++;
158 }
159 if (size == 0) {
160 std::cout << "Error: invalid argv provided" << std::endl;
161 exit(1);
162 }
163 // the name of the program only
164 _argv[0] = _argv[0].substr(_argv[0].find_last_of('/') + 1);
165 _top_level_command._name = _argv[0];
166 _top_level_command._key = _argv[0];
167 parser_program_name = _argv[0];
168 Arguments ret; // the parsed arg object to return
169 AP_StrVec args = _argv;
170 // call the recursive parse method in Command
171 if (!_top_level_command.parse(ret, args)) {
172 // deal with default command
173 if (!default_command.empty()) {
174 args = _argv;
175 args.insert(args.begin() + 1, default_command);
176 _top_level_command.parse(ret, args);
177 }
178 };
179 // if there is anything left, then output usage
180 if (!args.empty()) {
181 std::string msg = "Unknown command, option or args:";
182 for (const auto &it : args) {
183 msg = msg + " '" + it + "'";
184 }
185 // find the correct level to output help message
186 ArgParser::Command *command = &_top_level_command;
187 for (unsigned i = 1; i < _argv.size(); i++) {
188 auto it = command->_subcommand_list.find(_argv[i]);
189 if (it == command->_subcommand_list.end()) {
190 break;
191 }
192 command = &it->second;
193 }
194 command->help_message(msg);
195 }
196 return ret;
197}
198
199ArgParser::Command &
200ArgParser::require_commands()

Callers 8

mainFunction · 0.45
mainFunction · 0.45
test_ArgParser.ccFile · 0.45
TSUrlParseFunction · 0.45
TSCacheUrlSetFunction · 0.45
TSHttpTxnServerPushFunction · 0.45
TSHttpTxnRedoCacheLookupFunction · 0.45
mainFunction · 0.45

Calls 13

handle_argsFunction · 0.85
help_messageMethod · 0.80
set_envMethod · 0.80
clearMethod · 0.45
push_backMethod · 0.45
substrMethod · 0.45
emptyMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected