You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to create repeated option where user can select from one of allowed values. I'm using following code:
$ cat empty_group_value.m4
#!/bin/bash
# m4_ignore(
echo "This is just a script template, not the script (yet) - pass it to 'argbash' to fix this." >&2
exit 11 #)Created by argbash-init v2.4.1a
# ARG_HELP([<The general help message of my script>])
# ARG_OPTIONAL_REPEATED([myopt], , [foo,bar,])
# ARG_TYPE_GROUP_SET([MYGROUP], , [myopt], [foo,bar,])
# ARGBASH_GO
# [ <-- needed because of Argbash
echo "Value of --myopt: ${_arg_myopt[@]}"
# ] <-- needed because of Argbash
Non-empty single and repeated options works as expected:
$ ./empty_group_value.sh --myopt foo
Value of --myopt: foo
$ ./empty_group_value.sh --myopt foo --myopt bar
Value of --myopt: foo bar
But when I try to skip this option or even set it to empty string:
$ bash ./empty_group_value.sh
Value '' (of argument 'myopt') doesn't match the list of allowed values: 'foo', 'bar' and ''
$ bash ./empty_group_value.sh --myopt ''
Value '' (of argument 'myopt') doesn't match the list of allowed values: 'foo', 'bar' and ''
script doesn't accept that and even print misleading error message.
I'm running the code with latest updates of Red Hat Enterprise Linux 7.4:
$ bash --version
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ m4 --version
m4 (GNU M4) 1.4.16
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Rene' Seindal.
The text was updated successfully, but these errors were encountered:
Great, thank you for reporting this! The repeated arguments behavior is a bit tricky (see #12 ), but there is an obvious problem with the misleading error message.
I also assume that you have allowed passing empty values to the option only in order for the script to work if the option was not passed. In other words, you don't intend to pass empty values to the option on the command-line. Is it like that?
I also assume that you have allowed passing empty values to the option only in order for the script to work if the option was not passed. In other words, you don't intend to pass empty values to the option on the command-line. Is it like that?
Yes, ideally I'd love have that option optional. Empty value was just an other attempt to make it working somehow.
The argument validation should be performed during the assignment (now it is done after all assignments). This will take a little longer to fix, but it is surely a step in a right direction.
Thank you again, your use case very nicely exposes this minor design flaw.
Anyway, your example should now work with the master argbash.
I'd like to create repeated option where user can select from one of allowed values. I'm using following code:
After compilation:
Non-empty single and repeated options works as expected:
But when I try to skip this option or even set it to empty string:
script doesn't accept that and even print misleading error message.
I'm running the code with latest updates of Red Hat Enterprise Linux 7.4:
The text was updated successfully, but these errors were encountered: