Skip to content

ArgParser Fix: apply default values after dependency validation#12934

Open
brbzull0 wants to merge 1 commit intoapache:masterfrom
brbzull0:argparser_fix_dep_validation
Open

ArgParser Fix: apply default values after dependency validation#12934
brbzull0 wants to merge 1 commit intoapache:masterfrom
brbzull0:argparser_fix_dep_validation

Conversation

@brbzull0
Copy link
Contributor

@brbzull0 brbzull0 commented Mar 2, 2026

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 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().

Test also checks for Case sensitive short options which I needed to make sure they are working.

@brbzull0 brbzull0 added this to the 10.2.0 milestone Mar 2, 2026
@brbzull0 brbzull0 requested a review from Copilot March 2, 2026 12:38
@brbzull0 brbzull0 self-assigned this Mar 2, 2026
@brbzull0 brbzull0 added the Tools label Mar 2, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 after validate_dependencies() in Command::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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 modify Command state and is only reading _option_list, so it can be marked const (and declared const in the header) for correctness and to match the existing validate_* 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().
@brbzull0 brbzull0 force-pushed the argparser_fix_dep_validation branch from c74ff43 to 158bc56 Compare March 3, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants