kvz / bash3boilerplate

Templates to write better Bash scripts
http://bash3boilerplate.sh
MIT License
2.13k stars 199 forks source link

added automatic usage validation for required args #73

Closed mstreuhofer closed 7 years ago

mstreuhofer commented 7 years ago

If the description of an option contains the single word sentence 'Required.' it is understood as a required argument and automatic validation will make sure that it is set or end the script by calling help.

Alternatively, if the argument within the __usage string is {arg} instead of [arg] it is understood as a required argument and automatic validation will make sure that it is set or end the script by calling help (even if 'Required.' is not in the description).

Closes #22

mstreuhofer commented 7 years ago

referencing PR #65 here.

this PR is already rebased on vade-retro-eval assuming that there is no reason why it won't be merged.

zbeekman commented 7 years ago

this PR is already rebased on vade-retro-eval assuming that there is no reason why it won't be merged.

perfect, we'll deal with #72 first.

zbeekman commented 7 years ago

oy vey... I thought that we could just merge #72 and then this PR would update to show only the new commits/changes, but unfortunately that doesn't seem to be the case... any chance you could rebase just the changes for this PR on to kvz:origin?

mstreuhofer commented 7 years ago

that's what i was hoping too. i'll see what i can do to untangle this mess.

zbeekman commented 7 years ago

if not no worries... In the past I had thought that this worked, but perhaps they changed Github

mstreuhofer commented 7 years ago

but you know, github can (and did)show only the changes of the second commit if you asked nicely. so if it was just about the diff that would have worked as-is.

click on "Files changed" in the PR, top left you have a drop-down where you can choose to see the changes of all commits or only a single one.

no matter. i cleaned up and this PR has now one commit dealing only with the changes for automatic validation.

zbeekman commented 7 years ago

no matter. i cleaned up and this PR has now one commit dealing only with the changes for automatic validation.

Thanks for accommodating me.

Can you tell me about the two new files? These are tests that you wrote? Did you generate them automagically with @kvz's testing infrastructure or did you manually write one or both out?

zbeekman commented 7 years ago

@mstreuhofer PLEASE DO NOT TOUCH THIS PR (until I resolve issues discussed in #75)

zbeekman commented 7 years ago

@mstreuhofer OK, great we should be good to go here...

mstreuhofer commented 7 years ago

@zbeekman i wrote the test main-usage-validation/run.sh, made sure my code works as expected. then used the save-fixture feature of @kvz to create main-usage-validation.stdio

mstreuhofer commented 7 years ago

also: this PR feels happy to be of service in resurrecting the master branch. :) just checked with my local repo and as far as git is concerned nothing ever happened. good job! 👍

zbeekman commented 7 years ago

@mstreuhofer I like to think that I'm a git magician/wizzard: ✨ 🐇 🎩

In reality, maybe this is more accurate: :neckbeard:

PR LGTM!