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

ARG_TYPE_GROUP_SET doesn't accept empty values #26

Closed
pbabinca opened this issue Aug 21, 2017 · 4 comments
Closed

ARG_TYPE_GROUP_SET doesn't accept empty values #26

pbabinca opened this issue Aug 21, 2017 · 4 comments
Assignees
Labels
Milestone

Comments

@pbabinca
Copy link

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

After compilation:

$ argbash -o empty_group_value.sh empty_group_value.m4

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.
@matejak
Copy link
Owner

matejak commented Aug 25, 2017

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?

matejak added a commit that referenced this issue Aug 27, 2017
Validator was misbehaving when one of values could be blank.
Refs #26.
@pbabinca
Copy link
Author

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.

@matejak
Copy link
Owner

matejak commented Aug 28, 2017

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.

@matejak matejak self-assigned this Aug 28, 2017
@matejak matejak added the bug label Aug 28, 2017
@matejak matejak added this to the 2.5.0 milestone Aug 28, 2017
@pbabinca
Copy link
Author

pbabinca commented Sep 1, 2017

Thanks! I confirm this works as advertised now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants