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

b3bp sourced mode #61

Merged
merged 1 commit into from
Nov 9, 2016
Merged

b3bp sourced mode #61

merged 1 commit into from
Nov 9, 2016

Conversation

mstreuhofer
Copy link
Collaborator

If main.sh is being sourced instead of being executed it respects the
variables __usage and __helptext being defined beforehand. Its behaviour
will depend on the sourcing script. If __usage is defined but empty no
argument parsing is done. If __helptext is defined but empty no helptext
will be shown.

Logging support still exists as it did before. The environment variables
LOG_LEVEL and NO_COLOR are supported just as they were before.

@mstreuhofer
Copy link
Collaborator Author

This "sourced mode" does not change any behaviour of the script main.sh as it
was before -- as long as __usage is not already defined before main.sh being
sourced. This should cover all supported (documented) cases of downstream
usage.

The new script example.sh shows how b3bp can be used by downloading and
directly sourcing it without having to change anything, yet get the benefits of
getopts parsing, help and logging.

If main.sh is executed it behaves exactly as before. If it is sourced but no
__usage variable is defined it behaves exactly as before. Only if the
variable __usage is defined before main.sh is sourced the new logic
kicks in - in which case b3bp behaves likes a library (kind of).

If main.sh is being sourced instead of being executed it respects the
variables __usage and __helptext being defined beforehand. Its behaviour
will depend on the sourcing script. If __usage is defined but empty no
argument parsing is done. If __helptext is defined but empty no helptext
will be shown.

Logging support still exists as it did before. The environment variables
LOG_LEVEL and NO_COLOR are supported just as they were before.
@mstreuhofer
Copy link
Collaborator Author

if you are not totally against this PR i would go ahead and add tests for example.sh to cover this new sourced mode. also updating the documentation pointing out this new way of using b3bp would come your way.

@gdevenyi
Copy link
Contributor

gdevenyi commented Nov 8, 2016

This looks great, would allow me to integrate my usage of b3bp.sh more tightly with upstream

@mstreuhofer
Copy link
Collaborator Author

mstreuhofer commented Nov 8, 2016

that is the exact reason why i so furiously worked on all this changes ( #56 #57 and now #61 ). b3bp is really the boilerplate i need every time i start a new shell script. so much worked saved by just using it. but i am not a big fan of that copy-modify approach. what happens there is that you end up with 20 scripts which all started out as a copy of a different main.sh version, combined with different developers removing and changing as they will. deploying a new version of b3bp (e.g. super important bugfix) means changing 20 scripts instead of one "library".

@zbeekman
Copy link
Collaborator

zbeekman commented Nov 8, 2016

LGTM

@mstreuhofer
Copy link
Collaborator Author

Oh and btw.. i would even go so far as to rename main.sh to b3bp.sh. If it is used as a template most people rename it anyway and as a "library" it deserves a proper name. Who's with me? ;-)

@kvz kvz merged commit dfd799b into kvz:master Nov 9, 2016
@kvz
Copy link
Owner

kvz commented Nov 9, 2016

Thanks for your work @mstreuhofer!

i would even go so far as to rename main.sh to b3bp.sh

I need to think about that for a bit, I'm not immediately against it, I can say that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants