Comments (10)
Lets keep this open. I need to sleep on it, perhaps allow a string value in strict
so you can set an empty string or whatever else you want.
from bashly.
Well, thanks, but I have several issues with this proposal.
Issue 1: set -e
is needed by bashly.
The code generated by bashly itself (i.e. not user code) relies on set -e
to be set. In my experience, when you need it to NOT be set, it is a code smell that has multiple solutions other than calling set +e
.
In your example, the problem is not with the variable test [[ "${args["--force"]}" ]]
, but rather with the fact that you just use return
instead of return 0
.
This minor tweak makes it work without disabling set -e
:
#!/usr/bin/env bash
declare -A args
set -e
func() {
[[ "${args["--force"]}" ]] || return 0
echo "--force is set, continuing to do something"
}
# args["--force"]='1'
func
echo "end of script"
Also additional tip: Personally, I try to avoid shortcuts that look cool and compact. Be explicit:
func() {
# instead of this...
# [[ "${args["--force"]}" ]] || return 0
# ...do this
if [[ -z "${args["--force"]}" ]]; then
return 0
fi
echo "--force is set, continuing to do something"
}
Issue 2: Confusing options.
Having a setting that can accept true
, false
, disabled
, or none
is confusing, as three of these words are synonyms to false
. I do not like manual
.
Issue 3: This is overridable in user-land.
Finally, if someone for some reason does not care about my first argument, they can always override it as they see fit in the initialize.sh
. Of course this will result in set -e
followed immediately by set +e
, which - for someone who reads the script - might seem awkward, but it should serve as a sign that this should not be done.
It is ok to do this for debugging purposes of course, but I would not recommend leaving the final resulting script with it.
Bashly itself tries to stay out of your way, but still nudge you towards good standards and practices.
In my opinion, set -e
is a bare minimum safety measure - disabling it globally may cause your generated script to behave unexpectedly.
from bashly.
I disagree about the benefits of set -e
; as I noted, I had silent early termination which was substantially harder to debug than if the script had continued.
The BashFAQ also indicates that set -e
provides a tissue instead of a safety blanket: https://mywiki.wooledge.org/BashFAQ/105 because there’s a lot of corner cases. This is one of the reasons why I have explicitly not used set -e
on all but the simplest of shell scripts but instead explicitly check for errors on lines where failure or success matters.
If set -e
cannot be removed from Bashly safely, then I’ll probably have to make a prefix/suffix for all of my functions to disable/enable it for anything that is in my code, because I find set -e
unusable and untrustworthy. (And yes, I use a lot of subshell calls, which is one of the places where set -e
fails fairly hard.)
I agree with you about the confusing options; I do think that some other configuration option for this would be better.
from bashly.
Even in the link you posted, the very last Conclusion paragraph states two opposite opinions. On says use it, the other don't.
The set -e
option in bash is the closest thing to how all other languages operate - when there is an error, exit. Non zero return code in bash is error.
That said - bashly should not fight you if you feel otherwise.
I will execute all specs without set -e
first, see if things pass. If they do, then the door may be open to allowing users to set
whatever they want.
If you can take a look anywhere in the code (either the bashly source code, or your generated code) and see if there are things that might fail with set +e
, it would help expedite resolving this.
from bashly.
Specs pass with set +e
. So I suggest you set this in your initialize.sh
, and see if you have any issues.
If you do, please report them.
from bashly.
OK. Thanks for your thoughts on this.
from bashly.
I have changed the strict
setting to allow any string. This does not change how the true
or false
values work.
Can you take a look and see if it covers your use case in a satisfactory manner?
from bashly.
Looks great. Thanks again for such a useful project.
from bashly.
Excellent. I have built an edge docker, assuming you can use it (or the GitHub version) until next release (instructions).
Release will be coming soon.
from bashly.
Released in 1.0.1
from bashly.
Related Issues (20)
- shfmt fails when running with `--env production` HOT 2
- Allowed values of optional flags and arguments fail when `set -u` mode is set HOT 6
- Completions Install not working HOT 13
- Keep comments in ini config file HOT 1
- Here documents don't work HOT 6
- Update bashly schema to support `flag.unique` and `arg.unique` HOT 2
- Package external files with the generated bashly command HOT 3
- Allow default array when repeatable is true HOT 9
- Add support for array in `flag.default` and `arg.default` schema HOT 1
- JSON schema validation passes when it shouldn't HOT 12
- Add JSON schema tests to ensure the validation fails when it should HOT 1
- Whitelisted arg with default from environment HOT 6
- Add `environment_variable.allowed` whitelist HOT 1
- Update `inspect_args` to also print managed environment variables HOT 1
- Docker container does not have pandoc installed HOT 2
- Do not render `inspect_args` when `env` is set to `production` HOT 2
- Add key-value parameters HOT 6
- Add support for recursive --help HOT 6
- Build multi-arch docker HOT 2
- Default argument is not validated HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bashly.