Skip to content

Argparser variable arg option parsing fix/improvement. - #13570

Open
brbzull0 wants to merge 2 commits into
apache:masterfrom
brbzull0:argparser-variable-arg-option-parsing
Open

Argparser variable arg option parsing fix/improvement.#13570
brbzull0 wants to merge 2 commits into
apache:masterfrom
brbzull0:argparser-variable-arg-option-parsing

Conversation

@brbzull0

Copy link
Copy Markdown
Contributor

ArgParser options taking a variable number of values collected every remaining token, so
an option written after one was swallowed and never parsed: config reload -D ip_allow.id=foo -t mytok lost the token, while the reverse order worked. Collection now
stops at a token naming another declared option of the same command, and -- ends option
recognition so a dash-prefixed value stays expressible.

Also, --option=value took the name up to the first = but the value from the last, so
--directive=ip_allow.id=foo arrived as foo.

The second commit drops the -D-must-be-last workaround in traffic_ctl, makes an empty
-D/-d an error rather than a silent full reload, and corrects the docs.

Fixes: #13569

Damian Meden added 2 commits August 19, 2026 12:36
ArgParser options declared with MORE_THAN_ZERO_ARG_N or
MORE_THAN_ONE_ARG_N collected every remaining token, so an option
written after one of them was silently swallowed as a value and never
parsed. Collection now stops at a token naming another option of the
same command, "--" ends option recognition so a value can still start
with '-', and only the range actually consumed is erased.

Separately, the --option=value path took the name up to the first '='
but the value from the last one, truncating any value containing '='.
That made --directive=key.sub=val unusable, since directive values are
key=value pairs by definition.

Fixes: apache#13569
The guard rejecting directive values that start with '-' existed only
because variable-argument parsing swallowed any option written after
-D. That no longer happens, so the guard can only fire for a value the
caller passed deliberately, and its advice to place -D last is now
wrong. A malformed value is reported by the directive format check
instead.

Require values for both -D and -d. Supplying either with no values
built a request identical to a plain reload, silently widening a scoped
reload to every handler.

Also document that -D may appear anywhere among the options and can be
combined with -d, which the previous note said was impossible.
@brbzull0 brbzull0 self-assigned this Aug 19, 2026
@brbzull0 brbzull0 added Tools traffic_ctl traffic_ctl related work. labels Aug 19, 2026
@brbzull0

Copy link
Copy Markdown
Contributor Author

[approve ci debian]

@brbzull0

Copy link
Copy Markdown
Contributor Author

[approve ci]

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes two long-standing ts::ArgParser option-parsing defects that impacted traffic_ctl config reload (and other variable-argument options): variable-argument options no longer swallow subsequent options on the same command, -- now terminates option recognition so dash-prefixed values remain expressible, and --option=value parsing no longer truncates values containing embedded =.

Changes:

  • Update ArgParser variable-argument handling to stop consuming at the next registered option (and honor --), and fix --option=value value extraction to split on the first =.
  • Remove the -D “must be last” workaround behavior in traffic_ctl, and make empty -D / -d invocations explicit errors instead of silently degrading to full reloads.
  • Add unit + gold tests covering the corrected parsing behaviors and update traffic_ctl documentation accordingly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/tscore/ArgParser.cc Adjust variable-arg option collection logic, add registered-option detection, and fix --opt=... value splitting.
include/tscore/ArgParser.h Declare new Command helpers used for the updated parsing behavior.
src/tscore/unit_tests/test_ArgParser.cc Add unit coverage for variable-arg stop-at-next-option, -- handling, and embedded-= values.
src/traffic_ctl/CtrlCommands.cc Remove old -D ordering guard; error out on empty -d / -D to prevent silent full reload behavior.
tests/gold_tests/jsonrpc/config_reload_directive_cli.test.py Add end-to-end CLI parsing coverage for traffic_ctl config reload -D / -d interactions and --.
doc/appendices/command-line/traffic_ctl.en.rst Update operator guidance for -D/-d, including -- usage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/tscore/ArgParser.cc
Comment on lines +545 to +548
// 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.
@brbzull0

Copy link
Copy Markdown
Contributor Author

[approve ci centos]

@brbzull0
brbzull0 marked this pull request as ready for review August 21, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Tools traffic_ctl traffic_ctl related work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArgParser: variable-argument options consume following options, and --option=value truncates values containing '='

2 participants