Comparing version 1.0.221 to 1.0.222
{ | ||
"name": "bashlink", | ||
"version": "1.0.221", | ||
"version": "1.0.222", | ||
"description": "Testable, predictable and scoped code in bash.", | ||
@@ -52,2 +52,6 @@ "keywords": [ | ||
"main": "module.sh", | ||
"bin": { | ||
"document": "documentation.sh", | ||
"test": "doctest.sh" | ||
}, | ||
"repository": { | ||
@@ -54,0 +58,0 @@ "type": "git", |
168
readme.md
@@ -39,14 +39,14 @@ <!-- #!/usr/bin/env markdown | ||
```bash | ||
if [ -f "$(dirname "${BASH_SOURCE[0]}")/node_modules/bashlink/module.sh" ]; then | ||
# shellcheck disable=SC1090 | ||
source "$(dirname "${BASH_SOURCE[0]}")/node_modules/bashlink/module.sh" | ||
elif [ -f "/usr/lib/bashlink/module.sh" ]; then | ||
# shellcheck disable=SC1091 | ||
source "/usr/lib/bashlink/module.sh" | ||
else | ||
echo Needed bashlink library not found 1>&2 | ||
exit 1 | ||
fi | ||
bl.module.import bashlink.logging | ||
# Your code comes here. | ||
if [ -f "$(dirname "${BASH_SOURCE[0]}")/node_modules/bashlink/module.sh" ]; then | ||
# shellcheck disable=SC1090 | ||
source "$(dirname "${BASH_SOURCE[0]}")/node_modules/bashlink/module.sh" | ||
elif [ -f "/usr/lib/bashlink/module.sh" ]; then | ||
# shellcheck disable=SC1091 | ||
source "/usr/lib/bashlink/module.sh" | ||
else | ||
echo Needed bashlink library not found 1>&2 | ||
exit 1 | ||
fi | ||
bl.module.import bashlink.logging | ||
# Your code comes here. | ||
``` | ||
@@ -57,2 +57,31 @@ | ||
```bash | ||
declare -gr moduleName_bashlink_path="$( | ||
mktemp --directory --suffix -module-name-bashlink | ||
)/bashlink/" | ||
mkdir "$moduleName_bashlink_path" | ||
if curl \ | ||
https://raw.githubusercontent.com/thaibault/bashlink/master/module.sh \ | ||
>"${moduleName_bashlink_path}module.sh" | ||
then | ||
declare -gr bl_module_retrieve_remote_modules=true | ||
# shellcheck disable=SC1091 | ||
source "${moduleName_bashlink_path}module.sh" | ||
else | ||
echo Needed bashlink library not found 1>&2 | ||
rm --force --recursive "$moduleName_bashlink_path" | ||
exit 1 | ||
fi | ||
# Your standalone code comes here | ||
``` | ||
Or combine both to implement a very agnostic script. | ||
```bash | ||
if [ -f "$(dirname "${BASH_SOURCE[0]}")/node_modules/bashlink/module.sh" ]; then | ||
# shellcheck disable=SC1090 | ||
source "$(dirname "${BASH_SOURCE[0]}")/node_modules/bashlink/module.sh" | ||
elif [ -f "/usr/lib/bashlink/module.sh" ]; then | ||
# shellcheck disable=SC1091 | ||
source "/usr/lib/bashlink/module.sh" | ||
else | ||
declare -gr moduleName_bashlink_path="$( | ||
@@ -67,4 +96,4 @@ mktemp --directory --suffix -module-name-bashlink | ||
declare -gr bl_module_retrieve_remote_modules=true | ||
# shellcheck disable=SC1091 | ||
source "${moduleName_bashlink_path}module.sh" | ||
# shellcheck disable=SC1090 | ||
source "${moduleName_bashlink_path}/module.sh" | ||
else | ||
@@ -75,80 +104,51 @@ echo Needed bashlink library not found 1>&2 | ||
fi | ||
# Your standalone code comes here | ||
fi | ||
# Your portable code comes here. | ||
``` | ||
Or combine both to implement a very agnostic script. | ||
```bash | ||
if [ -f "$(dirname "${BASH_SOURCE[0]}")/node_modules/bashlink/module.sh" ]; then | ||
# shellcheck disable=SC1090 | ||
source "$(dirname "${BASH_SOURCE[0]}")/node_modules/bashlink/module.sh" | ||
elif [ -f "/usr/lib/bashlink/module.sh" ]; then | ||
# shellcheck disable=SC1091 | ||
source "/usr/lib/bashlink/module.sh" | ||
else | ||
declare -gr moduleName_bashlink_path="$( | ||
mktemp --directory --suffix -module-name-bashlink | ||
)/bashlink/" | ||
mkdir "$moduleName_bashlink_path" | ||
if curl \ | ||
https://raw.githubusercontent.com/thaibault/bashlink/master/module.sh \ | ||
>"${moduleName_bashlink_path}module.sh" | ||
then | ||
declare -gr bl_module_retrieve_remote_modules=true | ||
# shellcheck disable=SC1090 | ||
source "${moduleName_bashlink_path}/module.sh" | ||
else | ||
echo Needed bashlink library not found 1>&2 | ||
rm --force --recursive "$moduleName_bashlink_path" | ||
exit 1 | ||
fi | ||
fi | ||
# Your portable code comes here. | ||
``` | ||
Best practise (entry) module pattern: | ||
```bash | ||
if [ -f "$(dirname "${BASH_SOURCE[0]}")/node_modules/bashlink/module.sh" ]; then | ||
if [ -f "$(dirname "${BASH_SOURCE[0]}")/node_modules/bashlink/module.sh" ]; then | ||
# shellcheck disable=SC1090 | ||
source "$(dirname "${BASH_SOURCE[0]}")/node_modules/bashlink/module.sh" | ||
elif [ -f "/usr/lib/bashlink/module.sh" ]; then | ||
# shellcheck disable=SC1091 | ||
source "/usr/lib/bashlink/module.sh" | ||
else | ||
declare -gr moduleName_bashlink_path="$( | ||
mktemp --directory --suffix -module-name-bashlink | ||
)/bashlink/" | ||
mkdir "$moduleName_bashlink_path" | ||
if curl \ | ||
https://raw.githubusercontent.com/thaibault/bashlink/master/module.sh \ | ||
>"${moduleName_bashlink_path}module.sh" | ||
then | ||
declare -gr bl_module_retrieve_remote_modules=true | ||
# shellcheck disable=SC1090 | ||
source "$(dirname "${BASH_SOURCE[0]}")/node_modules/bashlink/module.sh" | ||
elif [ -f "/usr/lib/bashlink/module.sh" ]; then | ||
# shellcheck disable=SC1091 | ||
source "/usr/lib/bashlink/module.sh" | ||
source "${moduleName_bashlink_path}/module.sh" | ||
else | ||
declare -gr moduleName_bashlink_path="$( | ||
mktemp --directory --suffix -module-name-bashlink | ||
)/bashlink/" | ||
mkdir "$moduleName_bashlink_path" | ||
if curl \ | ||
https://raw.githubusercontent.com/thaibault/bashlink/master/module.sh \ | ||
>"${moduleName_bashlink_path}module.sh" | ||
then | ||
declare -gr bl_module_retrieve_remote_modules=true | ||
# shellcheck disable=SC1090 | ||
source "${moduleName_bashlink_path}/module.sh" | ||
else | ||
echo Needed bashlink library not found 1>&2 | ||
rm --force --recursive "$moduleName_bashlink_path" | ||
exit 1 | ||
fi | ||
echo Needed bashlink library not found 1>&2 | ||
rm --force --recursive "$moduleName_bashlink_path" | ||
exit 1 | ||
fi | ||
bl.module.import bashlink.exception | ||
bl.module.import bashlink.logging | ||
bl.module.import bashlink.tools | ||
alias moduleName.main=moduleName_main | ||
moduleName_main() { | ||
bl.exception.activate | ||
# Your entry code. | ||
bl.exception.deactivate | ||
} | ||
# Your module functions comes here. | ||
if bl.tools.is_main; then | ||
moduleName.main "$@" | ||
[ -d "$moduleName_bashlink_path" ] && \ | ||
rm --recursive "$moduleName_bashlink_path" | ||
# shellcheck disable=SC2154 | ||
[ -d "$bl_module_remote_module_cache_path" ] && \ | ||
rm --recursive "$bl_module_remote_module_cache_path" | ||
fi | ||
fi | ||
bl.module.import bashlink.exception | ||
bl.module.import bashlink.logging | ||
bl.module.import bashlink.tools | ||
alias moduleName.main=moduleName_main | ||
moduleName_main() { | ||
bl.exception.activate | ||
# Your entry code. | ||
bl.exception.deactivate | ||
} | ||
# Your module functions comes here. | ||
if bl.tools.is_main; then | ||
moduleName.main "$@" | ||
[ -d "$moduleName_bashlink_path" ] && \ | ||
rm --recursive "$moduleName_bashlink_path" | ||
# shellcheck disable=SC2154 | ||
[ -d "$bl_module_remote_module_cache_path" ] && \ | ||
rm --recursive "$bl_module_remote_module_cache_path" | ||
fi | ||
``` | ||
@@ -155,0 +155,0 @@ |
256726