Skip to content

Make zparseopts section argument extraction more robust#2

Merged
bgreg merged 2 commits into
fix/weather-and-word-of-day-improvementsfrom
copilot/sub-pr-1
Dec 22, 2025
Merged

Make zparseopts section argument extraction more robust#2
bgreg merged 2 commits into
fix/weather-and-word-of-day-improvementsfrom
copilot/sub-pr-1

Conversation

Copilot AI commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

The zparseopts syntax -section:=section_arg populates an array with both option name (index 1) and value (index 2). Hardcoding section_arg[2] is fragile if zparseopts behavior changes.

Changes:

  • Use section_arg[-1] to extract the last element instead of hardcoded index 2
  • Validate array has at least 2 elements before access
  • Return error when --section is provided without a value
# Before
if [[ ${#section_arg[@]} -gt 0 ]]; then
  local section_name="${section_arg[2]}"
  _run_single_section "$section_name"
fi

# After
if [[ ${#section_arg[@]} -gt 0 ]]; then
  if [[ ${#section_arg[@]} -lt 2 ]]; then
    echo "Error: --section requires a value" >&2
    return 1
  fi
  local section_name="${section_arg[-1]}"
  _run_single_section "$section_name"
fi

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Use last element instead of hardcoded index 2, add validation for array length,
and provide clear error message when --section value is missing.

Co-authored-by: bgreg <3711139+bgreg@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on weather geolocation and offline word of day Make zparseopts section argument extraction more robust Dec 22, 2025
Copilot AI requested a review from bgreg December 22, 2025 22:50
@bgreg bgreg marked this pull request as ready for review December 22, 2025 22:52
@bgreg bgreg merged commit 0708c13 into fix/weather-and-word-of-day-improvements Dec 22, 2025
@bgreg bgreg deleted the copilot/sub-pr-1 branch December 22, 2025 22:52
bgreg added a commit that referenced this pull request Mar 31, 2026
Make zparseopts section argument extraction more robust
bgreg added a commit that referenced this pull request Jun 30, 2026
Make zparseopts section argument extraction more robust
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants