-
Notifications
You must be signed in to change notification settings - Fork 198
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
Enable long, GNU style options RE: issue-1 #3
Conversation
-t --temp [arg] Location of tempfile. Default="/tmp/bar" | ||
-v Enable verbose mode, print script as it is executed | ||
-d --debug Enables debug mode | ||
-h --help This page |
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.
The second field is examined for leading --
if found, that is determined to be a long version of the option. N.B. All long options must have corresponding short options, but not vice-versa. This could be changed without too much work, but for now, this is more consistent with the existing code and intentions, IMO.
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.
A very acceptable compromise imo too
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.
👍
Looking good so far @zbeekman! On what OS are you testing this? I'm just worried a bit that you said standard sed. I think it's either GNU or BSD, and both are quite different, where GNU is standard on most Linux distros and BSD is present on OSX. I suppose we should set up some kind of Travis CI environment and see if we can execute this on a few environments. |
Thanks!
Yes I am on OS X which uses the BSD flavored
I agree, however, my time is severely limited at the moment, and I probably can't do anything fancier than some manual testing on OS X and RHEL 5/6. |
Much appreciated! I forked off the issue of CI into #4 |
This is how I suggest we proceed: My intention is to push one or two additional commits, to finalize things here, and then once you think everything looks good, and I think everything looks good, I'll squash them down into one commit and force push them to my fork. After that, unless you have additional concerns, you can go ahead and merge. Does that work for you? |
sounds great! |
I'll also rebase, since it looks like you've pushed some travis-ci commits to master. That way, some CI tests should get run on this PR, I hope. 🍀 |
Leave the failing build to me, it's expected to fail until I rerun fixtures for your changes. |
Alternatively, you could run |
What does the |
# Bash will remember & return the highest exitcode in a chain of pipes. | ||
# This way you can catch the error in case mysqldump fails in `mysqldump |gzip` | ||
set -o pipefail | ||
|
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.
More robust error checking from the beginning
Travis-CI tests look good, I just need to adjust the expected output for the tests. |
This is the output when I run it locally, FYI.
|
Sorry about that, I only just added these things and used half a brain apparently. Added a fix for that in 7a9d116.
Short of the time to implement unit tests, I decided to slap a poor man's alternative on top of this in the form of acceptance tests.
This way, any changes to the flow or success, get noticed. And we have to check them into Git if we agree. |
Other than ensuring the tests pass, and squashing/rebasing this commit, I think things look good. Regarding testing locally, I tried rebasing on your latest pushed fixes, but I still encounter an error. Please see my comment on 63cd89a At your leisure, please review the latest commits I pushed. I'm waiting on squash and rebase so you can see my comments on the diffs. Once you give me a "LGTM" or similar, I will squash, rebase and force push. After that we can address any local test failures, if need be. |
Okay just reviewed all of it again and it lgtm! Thanks alot for this improvement. I'll be waiting on the squashed version and merge this. Wether you succeed with the tests or no, if you don't I'll patch things up after merging, this is my mess ;) |
- Enable long, GNU style options, fixes #1 - *CAVEAT* A short option must be preset for every long option; but every short option need *not* have a long option - No BASH 4 features were added, works with bash 3 and standard sed and awk - `--` is still respected as the separator between options and arguments - Use `awk` only instead of `awk` and `sed` for parsing short options from usage string - Enable errexit, nounset and pipefail at the top
ATTN: @kvz I think I did this correctly, but please look through the Travis-CI output nonetheless.
Test pass locally with your latest changes. I think I figured out how to update anticipated test results too... 🙏 hopefully Travis-CI tests will pass. I'm happy to have this merged if you are. ⚡ |
Great job @zbeekman, can't thank you enough. Merging this. I won't always have time to maintain this project so I also gave you commit access to make any changes you'd like. Looking at your work I'm not concerned that will end in a disaster :) |
Enable long, GNU style options RE: issue-1
🙇 many thanks @kvz |
Trying this locally on OSX @zbeekman and getting: kvz at mbp in ~/code/bash3boilerplate on master
$ ./main.sh -d
awk: syntax error at source line 1
context is
>>> match($1,"^-.", <<<
awk: bailing out at source line 1
2016-02-16 20:07:19 UTC [ info] Cleaning up. Done What Mine is $ awk --version
awk version 20070501 |
Pending final review and CI tests, @kvz please feel free to merge
but every short option need not have a long option
awk
--
is still respected as the separator between options and argumentsawk
only instead ofawk
andsed
for parsing short optionsfrom usage string
errexit
,nounset
andpipefail
at the top