1) github repositoy: https://github.com/carlobaldassi/bash_optparse
2) quick explanation with download links: https://github.com/carlobaldassi/bash_optparse/wiki
3) a simple example file: https://github.com/carlobaldassi/bash_optparse/raw/master/doc/example_script_simple
Comments / suggestions are welcome.
For relatively simple tasks, I like to keep a file of custom global bash functions rather than a directory of scripts. Some of the functions use getopt for option parsing. Since getopt lacks readability and auto-help, I've been looking for another solution. It would be great to use bash_optparse form a function.
Since bash_optparser calls exit, it can't be used from functions, since exit causes the terminal window to close. After an error within a function, I usually call return, to leave the function, without killing the entire shell.
Can you suggest a low impact work around? If not, would you consider a SETTINGS option for use within functions?
Thanks for the feedback!
Concerning the issue about using it from within a function: I'm aware
of this, but I have no workaround to suggest at the moment. Because of
the way bash_optparse works, it is not trivial to come up with an
elegant solution like adding a simple SETTING, either. I shall put
this into my to-do list and think about how this could be addressed; I
hope to have a solution soon.
Update: usage from within functions is now possible. There's an additional example file in the doc directory which demonstrates this. Note: everything seems to work fine in my tests, but I'd still consider this feature as experimental: if anybody tries this, please report any problems which may arise, thanks.