Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-18] Resolves "unbound variable" errors #32

Merged
merged 17 commits into from
Dec 17, 2024
Merged

[GH-18] Resolves "unbound variable" errors #32

merged 17 commits into from
Dec 17, 2024

Conversation

UrsaDK
Copy link
Owner

@UrsaDK UrsaDK commented 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.

billyzkid and others added 17 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
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.
@UrsaDK UrsaDK merged commit 936fdd5 into master Dec 17, 2024
3 checks passed
@UrsaDK UrsaDK deleted the gh-18 branch December 17, 2024 17:25
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 (97f57b9).
Report is 1 commits behind head on master.

Additional details and impacted files

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