ArgParser Fix: apply default values after dependency validation#12934
Open
brbzull0 wants to merge 1 commit intoapache:masterfrom
Open
ArgParser Fix: apply default values after dependency validation#12934brbzull0 wants to merge 1 commit intoapache:masterfrom
brbzull0 wants to merge 1 commit intoapache:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates ts::ArgParser parsing flow so option default values are applied after dependency validation, preventing options with defaults from being treated as “explicitly used” during with_required() checks.
Changes:
- Extracted default-value population into
ArgParser::Command::apply_option_defaults()and invoked it aftervalidate_dependencies()inCommand::parse(). - Added unit tests to confirm (1) short option case-sensitivity and (2)
with_required()is not triggered by defaulted-but-not-specified options.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/tscore/unit_tests/test_ArgParser.cc |
Adds coverage for short-option case sensitivity and for dependency validation not being triggered by default values. |
src/tscore/ArgParser.cc |
Moves default application to a dedicated helper and runs it after dependency validation. |
include/tscore/ArgParser.h |
Declares the new apply_option_defaults() helper on ArgParser::Command. |
5 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
src/tscore/ArgParser.cc:745
apply_option_defaults()doesn't modifyCommandstate and is only reading_option_list, so it can be markedconst(and declaredconstin the header) for correctness and to match the existingvalidate_*helpers. This also prevents accidental future mutation of command state during default application.
void
ArgParser::Command::apply_option_defaults(Arguments &ret)
{
for (const auto &it : _option_list) {
if (!it.second.default_value.empty() && ret.get(it.second.key).empty()) {
std::istringstream ss(it.second.default_value);
std::string token;
while (std::getline(ss, token, ' ')) {
ret.append_arg(it.second.key, token);
}
}
}
}
validate_dependencies() incorrectly triggers on options that have default values but were not explicitly passed by the user. The root cause is that append_option_data() populates default values into the Arguments map before validate_dependencies() runs. When validate_dependencies() calls ret.get(key) for an option with a default, the lookup finds the entry and sets _is_called = true, making the option appear "used" even though the user never specified it on the command line. Fix by extracting the default-value loop into apply_option_defaults() and calling it after validate_dependencies() in parse().
c74ff43 to
158bc56
Compare
cmcfarlen
approved these changes
Mar 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ArgParser: apply default values after dependency validation
validate_dependencies()incorrectly triggers on options that have default values but were not explicitly passed by the user.The root cause is that
append_option_data()populates default values into the Arguments map beforevalidate_dependencies()runs. Whenvalidate_dependencies()callsret.get(key)for an option with a default, the lookup finds the entry and sets_is_called = true, making the option appear "used" even though the user never specified it on the command line.Fix by extracting the default-value loop into
apply_option_defaults()and calling it aftervalidate_dependencies()inparse().Test also checks for
Case sensitive short optionswhich I needed to make sure they are working.