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

Unexpected behavior with default true booleans #51

Open
theanine opened this issue Oct 1, 2019 · 1 comment
Open

Unexpected behavior with default true booleans #51

theanine opened this issue Oct 1, 2019 · 1 comment
Assignees
Labels
Milestone

Comments

@theanine
Copy link

theanine commented Oct 1, 2019

Test program here:

FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
if [ ${FLAGS_foo} -eq ${FLAGS_TRUE} ]; then
	echo "true"
else
	echo "false"
fi

With:

DEFINE_boolean foo false "bar" "f"

Output (as expected):

$ foo-test.sh
false
$ foo-test.sh -f
true
$ foo-test.sh --nof
false
$ foo-test.sh --foo
true
$ foo-test.sh --nofoo
false

With:

DEFINE_boolean foo true "bar" "f"

Output (unexpected):

$ foo-test.sh
true
$ foo-test.sh -f
false
$ foo-test.sh --nof
false
$ foo-test.sh --foo
true
$ foo-test.sh --nofoo
false

If it's not obvious from the above output, the part that is unexpected is the output of foo-test.sh -f

@kward
Copy link
Owner

kward commented Apr 13, 2020

I agree, that is confusing.

I propose fixing this by enforcing the convention that single-character booleans, when passed, will always give a true value. Unfortunately, there is no good way to negate them, but this can be handled in code by following the convention that boolean values should always default to false, requiring them to be passed as flags to enable them.

Thoughts?

@kward kward added this to the 1.3.0 milestone Apr 13, 2020
@kward kward self-assigned this Aug 21, 2023
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