Skip to content

Conversation

billyzkid
Copy link
Contributor

This PR adds a check that prevents an error when nounset is enabled (set -u) and !OPTIND is unbound, i.e. when there are no more arguments left to process and getopts_long encounters a final option that is missing a required argument. This matches the behavior of the builtin getopts command.

billyzkid and others added 12 commits August 23, 2023 09:17
This PR clears OPTARG (as opposed to `unset OPTARG`) for a valid long option without a required argument (e.g. `--charlie`). I believe this matches the behavior of builtin `getopts` for valid short options without an argument.
Clear vs. unset OPTARG for valid long option without argument
Redeclare OPTARG instead of clear
@UrsaDK UrsaDK changed the base branch from master to gh-18 December 17, 2024 16:26
@UrsaDK UrsaDK merged commit cbe9795 into UrsaDK:gh-18 Dec 17, 2024
3 checks passed
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (737a918) to head (ea81a25).
Report is 16 commits behind head on gh-18.

Additional details and impacted files

UrsaDK added a commit that referenced this pull request Dec 17, 2024
This PR adds checks to prevent getopts_long errors when `set -u` (shorthand for `set -o nounset`) is enabled. This setting ensures that accessing an unset or undefined variable triggers an error, which helps catch scripting mistakes and avoid unintended behaviour caused by typos or missing variables.


Co-authored-by: Will Allan <billyzkid@yahoo.com>
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