-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Do not accept options after positional when ARG_LEFTOVERS is specified #114
Comments
Hello, I think that I understand your use case and your request. |
Thanks for the answer. I also tried the I think this is a real use case that can make Argbash more complete. For example, I see this behavior used so widely that is weird to see it does not match the standards (or a known exception of it). Despite of it, I completely agree with you on that: if it doesn't match the standards, this behavior must be defined in the template. |
An workaround I'm using, is to manually editing the generated parse_commandline()
{
[...]
*)
_last_positional="$1"
_positionals+=("$_last_positional")
_positionals_count=$((_positionals_count + 1))
set -- "${@:1:1}" "--" "${@:2}"
;;
esac
shift
done
} The difference is the What it does is that it automatically puts |
Simple example, how can I do something like
docker run
does? You have to specify all the options afterrun
, and then the positional argument which is the image. After, it passes all the remaining arguments (options or not) to the container's entrypoint.The only way I could accomplish this is by using
ARG_POSITIONAL_DOUBLEDASH
in my templates, then ensuring the customers don't forget to put--
. Example:Imagine I have a
entrypoint.sh
in my docker image made with argbash. And also, I have another script calledrun.sh
(also argbash powered), which finds a script in the container and run it. So bothentrypoint.sh
andrun.sh
needs ARG_LEFTOVERS.docker run -ti felipe run.sh another_script.sh -v
It was supposed to pass
-v
as argument ofanother_script
, but what happens is that the-v
is consumed by theentrypoint.sh
, which prints its version instead of runningrun.sh
. The way to solve is:docker run -ti felipe -- run.sh -- another_script.sh -v
But this doesn't seems elegant. I think the best approach would be to treat all the arguments after the positionals as leftovers, just if
ARG_LEFTOVERS
is specified in template.The text was updated successfully, but these errors were encountered: