Comments (4)
Hi @pilak,
Using even the default getops
inside a function is not exactly straight forward... But I'll see if I can add some test coverage for this use-case and workout what's going on with BASH_ARGV.
One thing that would really help is a simple example of how you're using getopts_long
, as I'm not entirely sure what you mean by "nested function". Are you talking about a function within a function? Also, are you attempting to process arguments supplied to the script or to the function?
from getopts_long.
@UrsaDK : It is possible to use builtin getopts
inside a function:
foo () {
OPTIND=1
while getopts ':ab:' OPT ; do
case "$OPT" in
a) a_stuff ;;
b) b_stuff=$OPTARG ;;
...
However, with getopts_long
, you can't do a similar loop, because, in the way you currently use OPTIND, you are looking through the arguments of the overall script, not the arguments of the function.
If you want to use getopts_long
in a subcommand, for example passing the shifted arguments to foo
using foo "$@"
, this is problematic.
from getopts_long.
Answering my own question, you already handle this.
foo () {
OPTIND=1
while getopts_long ':ab: alpha bravo:' OPT "$@"; do
case "$OPT" in
a|alpha) a_stuff=1 ;;
b|bravo) b_stuff=$OPTARG ;;
...
from getopts_long.
Thanks for following this up with an answer @dodecatheon!
I think, since this question came up twice now, I should probably add it to the README, and maybe even include it as a separate scenario in the tests. I'll add it to me TODO list!
For now, I'm going to resolve this as "Works as expected" since there isn't a difference between the way the original geopts
and my getopts_long
behave in this use case.
from getopts_long.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from getopts_long.