Copilot commented on code in PR #13570:
URL: https://github.com/apache/trafficserver/pull/13570#discussion_r3819571024
##########
src/tscore/ArgParser.cc:
##########
@@ -518,23 +518,56 @@ ArgParser::Command::output_option() const
}
}
+bool
+ArgParser::Command::is_registered_option(std::string const &token) const
+{
+ if (_option_list.find(token) != _option_list.end() ||
_option_map.find(token) != _option_map.end()) {
+ return true;
+ }
+ // The --option=value form.
+ if (token.size() > 2 && token[0] == '-' && token[1] == '-') {
+ if (auto const pos = token.find_first_of('='); pos != std::string::npos) {
+ return _option_list.find(token.substr(0, pos)) != _option_list.end();
+ }
+ }
+ return false;
+}
+
// helper method to handle the arguments and put them nicely in arguments
// can be switched to ts::errata
-static std::string
-handle_args(Arguments &ret, AP_StrVec &args, std::string const &name, unsigned
arg_num, unsigned &index)
+std::string
+ArgParser::Command::handle_args(Arguments &ret, AP_StrVec &args, std::string
const &name, unsigned arg_num, unsigned &index) const
{
ArgumentData data;
ret.append(name, data);
// handle the args
if (arg_num == MORE_THAN_ZERO_ARG_N || arg_num == MORE_THAN_ONE_ARG_N) {
- // infinite arguments
- if (arg_num == MORE_THAN_ONE_ARG_N && args.size() <= index + 1) {
- return "at least one argument expected by " + name;
- }
- for (unsigned j = index + 1; j < args.size(); j++) {
+ // Variable number of arguments. Stop collecting at a token that names
another option
+ // of this command, so that following options and this command's own
positional
+ // arguments are left in place for the caller. A "--" token ends option
recognition,
+ // which is how a value that starts with '-' can be passed.
Review Comment:
The comment claims variable-argument option parsing leaves this command's
positional arguments in place for the caller, but the implementation only stops
at *registered options* (or after "--"). Positional tokens that don't match an
option name are still collected as values and erased, so this wording is
misleading.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]