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

Parse Function Arguments as well as Command Arguments #53

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

EdwardOst
Copy link

The basic getoptions is designed for use with shell scripts but is not fully compatible for use with functions. The generated parser initializes the parameters in the outer shell rather than inside the parser function. This is ok for shell scripts, but unnecessarily pollutes the shell variables. It is a leaky abstraction.

The intent is for the parent function for which we are generating a parser to declare and bound the scope of the function parameters. Since they are only initialized rather than declared in the generated parser this will prevent pollution of the shell space.

This does not impact command scripts since the initialized variables will have shell global scope anyway, and will therefore be available to the calling script.

The change is actually a one liner moving the start of the generated parser function before the initialization of the variables.

The example shows how to use the modified getoptions to parse function arguments. It generates the parser a single time in a lazy load manner the first time the function is called.

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.

None yet

1 participant