-
-
Notifications
You must be signed in to change notification settings - Fork 93
Allow empty string as flag argument #122
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
Conversation
Why is this needed? |
I tried to explain in the PR description, is there something that isn't clear? |
Yes. Why is it needed to allow a parameter to receive an empty string? What is the use case that this solves? If To add to this - I never once had to use
Everywhere I look, this is an "abort" condition. Although, this is slightly different than what Bashly is doing, it is bashly's responsibility to ensure that once it reaches the user code, everything is valid. This is considered invalid in my mind. |
It solves the use case of passing an empty string as a parameter. This is very distinct from not passing the parameter at all. Some random examples I found in the oilshell corpus: git rev-parse --prefix "" -- top sub1/file1 whiptail --title "$WHIP_TITLE" --backtitle "$WHIP_BACKTITLE" --menu "" --default-item "$MENU_MAIN_LASTITEM" --cancel-button "Exit" adduser --disabled-password --gecos '' mesos ssh-keygen -q -N '' -t ed25519 -f $keyfile cut -d '' -f1 pathchk -P '' git commit -m "" --allow-empty-message git tag -m "" tag-name ldapsearch -R -T -h "$dc" $ldap_args -b "" -s base "" It is very surprising to me as a script author that bashly is attempting to perform validation on my script's arguments without any context as to what they're used for. If an empty string is not part of my script's domain, I can check that case along with other validations on the value; but when it is part of the valid domain, I need Bashly to let it through in order for my script to work properly. It's also worth noting that the examples you provide are both clearly explicit validations: the error is not "you are missing an argument" but "you have passed an argument, but its value is not valid in this specific context". |
All are either niche examples, or bad design in my mind. The only use case that might be relevant is for scripts that operate on strings, where clearly I feel that for 90% of cases, I am not yet convinced that this PR makes bashly better. |
Niche they may be, but that is not the same as useless.
Personally, I think the design is perfectly good, though that is of course a matter of taste.
Because If git did what you propose (allowing empty messages unconditionally, and defaulting to an empty message if
All scripts operate on strings; I assume here that you mean “strings which do not have a deeper semantic meaning, like file paths or docker tags.” It is of course correct that there are certain types of string values for which the empty string is not a valid value (and that this is a very common validation), but (a) many of these string types also have other validations anyway and (b) it is equally true that there are many string types for which this is not the case.
10% is quite a lot of cases to make impossible.
Well, hopefully I can convince you :-) As I mentioned, this is actually some of the same changes as in #113 which you have indicated approval of, but when I noticed I needed this empty string case in my script I thought it would be useful to raise it as a separate discussion. |
Lets simplify the argument. From the bashly manifesto:
More often than not, for most users, with most flags - an empty string is an invalid input. Although I am yet to see a use case that does not have a better solution, I can accept that it is a matter of style. How about enabling these empty params conditioanlly, as follows:
I might also be open to the idea that the default behavior should be How do you feel about that? |
@wolfgang42 - since I much rather work on small PRs, dealing with small concepts, how do you feel about the following:
Deal? |
I was actually thinking more about this last night and was going to suggest Your plan sounds good, except—I am not sure about making empty strings allowed and then later adding the The extra test line was mainly to demonstrate the point, for discussion; I can definitely make a proper fixture test for both flags and arguments, if we decide that this PR is a good approach. Incidentally, I just want to say: I have sometimes taken a somewhat combative tone in these discussions, because I have quite strong opinions about how some of these things should work, but I appreciate the way that you also have similarly strong opinions and a cohesive vision for how Bashly should work. I feel that, though it may take a while to get there, the final result will be the stronger for it. |
I was actually moving closer to your original opinion, meaning I suggested to implement this as a new default, and later, if at all, add However - if you do not feel strongly that you need this empty feature, I would leave it alone for now. In addition, I saw #125 and I love it! I feel this is definitely the way to go.
Although this is not yet 1.x, I still prefer not to break compatibility.
This is perfectly fine, I haven't noticed... I feel we both have strong opinions, loosely held. Given new facts, I am happy to change my mind. However, I have learned that there is no way to make everybody happy, and the only way to keep a product solid, is to defend its values - otherwise, it just becomes a mix of different opinions and patchy features.
Likewise. I definitely see the value in these discussions, and your arguments are always well outlined, so it gives me another perspective about how bashly is used by someone other than myself. In light of #125 - should we close this one for now, or do you prefer to implement this "allow empty as a default behavior" before we do? |
Ah, that sounds much less confusing.
I do need empty argument support for my use case; right now I'm using a fork with this PR in it.
As you said, it is better to work with small PRs. I think that this is a prerequisite for adding validation anyway (at least, I take some time soon to clean this one up per your plan #122 (comment) above so it can be merged. |
Sounds great. |
The empty argument is, in niche case, the only way to respect POSIX guidelines on utility argument syntaxes, guideline that shaped much of our aquired tastes up to now.
An empty argument permit fullfiling this rule. Later validation or de-facto broken usage is up to deal with it. |
@DannyBen I've created a fixture test and removed the example test I had added. It turns out that positional arguments already worked, but I have added a test case for them anyway. I believe this PR is ready for your review. |
Hmm - don't know why GitHub didn't notify me on this - just saw it now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had one comment, and there is the issue of the conflicted files,
- long: --flag | ||
arg: value | ||
args: | ||
- name: arg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we add another arg, so that we have one optional and one required? As I have learned in #130, there are two places these args are handled.
@wolfgang42 - I can confirm this is not working as expected with the below YAML: name: cli
help: Sample application
version: 0.1.0
commands:
- name: test
help: Run test
flags:
- long: --flag
arg: value
args:
- name: required_arg
required: true
- name: optional_arg I think this YAML should be used in the fixture test, with these test commands: ./cli test a b --flag c
./cli test ''
./cli test '' --flag ''
./cli test '' '' --flag '' (I played with it a little in #135). |
I am closing this, as it is superseded by #135. |
Allow empty string as argument (replacing #122)
(This overlaps with the changes in #113, but came up in an unrelated context and seemed worthy of discussion on its own merits.)
I was explicitly passing in the empty string as an argument to a flag, but bashly treated this as though the argument was absent, which is not the behavior I wanted. This PR changes that so that it will accept the empty string correctly, and adds a spec using the example of a blank password.
I think the same change should also be made to non-flag arguments, though I haven't investigated that case yet.