aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/logging.bash82
-rw-r--r--lib/util.bash57
2 files changed, 119 insertions, 20 deletions
diff --git a/lib/logging.bash b/lib/logging.bash
index 37b947d..b54db65 100644
--- a/lib/logging.bash
+++ b/lib/logging.bash
@@ -26,10 +26,78 @@ log() {
##
## Log a debug-level message. This message only shows if BASHTARD_DEBUG
## evaluates to a truthy value.
-debug() { [[ -n $BASHTARD_DEBUG ]] && log "$1" "$(printf "\e[0;37m%s" "${@:2}")" ; }
-info() { log "$1" "$(printf "\e[m%s" "${@:2}")" ; }
-notice() { log "$1" "$(printf "\e[0;34m%s" "${@:2}")" ; }
-warn() { log "$1" "$(printf "\e[1;39m%s" "${@:2}")" ; }
-crit() { log "$1" "$(printf "\e[0;33m%s" "${@:2}")" ; }
-alert() { log "$1" "$(printf "\e[0;31m%s" "${@:2}")" ; }
-emerg() { log "$1" "$(printf "\e[1;31m%s" "${@:2}")" ; }
+debug() {
+ [[ -n $BASHTARD_DEBUG ]] && log "$1" "$(printf "\e[0;37m%s" "${@:2}")"
+}
+
+## :bocs:
+## :section: 3
+## :heading: functions
+## :name: info
+## :param: The system to log for.
+## :param: The message to log.
+##
+## Log an info-level message.
+info() {
+ log "$1" "$(printf "\e[m%s" "${@:2}")"
+}
+
+## :bocs:
+## :section: 3
+## :heading: functions
+## :name: notice
+## :param: The system to log for.
+## :param: The message to log.
+##
+## Log an notice-level message.
+notice() {
+ log "$1" "$(printf "\e[0;34m%s" "${@:2}")"
+}
+
+## :bocs:
+## :section: 3
+## :heading: functions
+## :name: warn
+## :param: The system to log for.
+## :param: The message to log.
+##
+## Log an warning-level message.
+warn() {
+ log "$1" "$(printf "\e[1;39m%s" "${@:2}")"
+}
+
+## :bocs:
+## :section: 3
+## :heading: functions
+## :name: crit
+## :param: The system to log for.
+## :param: The message to log.
+##
+## Log an critical-level message.
+crit() {
+ log "$1" "$(printf "\e[0;33m%s" "${@:2}")"
+}
+
+## :bocs:
+## :section: 3
+## :heading: functions
+## :name: alert
+## :param: The system to log for.
+## :param: The message to log.
+##
+## Log an alert-level message.
+alert() {
+ log "$1" "$(printf "\e[0;31m%s" "${@:2}")"
+}
+
+## :bocs:
+## :section: 3
+## :heading: functions
+## :name: emerg
+## :param: The system to log for.
+## :param: The message to log.
+##
+## Log an emergency-level message.
+emerg() {
+ log "$1" "$(printf "\e[1;31m%s" "${@:2}")"
+}
diff --git a/lib/util.bash b/lib/util.bash
index 4a9775b..fa790a1 100644
--- a/lib/util.bash
+++ b/lib/util.bash
@@ -255,8 +255,14 @@ file_template()
sed -f "$sedfile" "$file"
}
-# Check if the first argument given appears in the list of all following
-# arguments.
+## :bocs:
+## :section: 3
+## :heading: functions
+## :name: in_args
+## :param: The needle to search for.
+## :params: Zero or more arguments, representing the haystack.
+##
+## Search for a given needle in a given haystack. Returns 0 if found, 1 if not.
in_args() {
local needle="$1"
shift
@@ -269,9 +275,15 @@ in_args() {
return 1
}
-# Join a list of arguments into a single string. By default, this will join
-# using a ",", but you can set a different character using -c. Note that this
-# only joins with a single character, not a string of characters.
+## :bocs:
+## :section: 3
+## :heading: functions
+## :name: join_args
+## :params: The values which need to be joined together
+## :opt: -c The character used as glue
+##
+## Joins together the given arguments using the glue character given with -o.
+## If no glue character is specified, a comma (,) will be used.
join_args() {
local OPTIND
local IFS=","
@@ -289,8 +301,17 @@ join_args() {
printf "%s" "$*"
}
-# Convenience function to easily get paths used by the playbook, or to use in
-# your playbook.
+## :bocs:
+## :section: 3
+## :heading: functions
+## :name: playbook_path
+## :param: Path value to retrieve
+##
+## Gets the absolute path to a path useful in playbook writing. The given
+## parameter can be one of the following:
+##
+## - `base` - The base directory of the playbook
+## - `data` - The data directory of the playbook
playbook_path() {
if [[ -z "$BASHTARD_PLAYBOOK" ]]
then
@@ -302,13 +323,18 @@ playbook_path() {
base) printf "%s/playbooks.d/%s" "$BASHTARD_ETCDIR" "$BASHTARD_PLAYBOOK" ;;
data) printf "%s/data.d/%s" "$BASHTARD_ETCDIR" "$BASHTARD_PLAYBOOK" ;;
*)
- crit "bashtard/playbook_path" "Invalid path '$1'"
+ crit "bashtard/playbook_path" "Invalid path value '$1'"
return 1
esac
}
-# Create a temporary directory. Similar to tempfile, but you'll get a directory
-# instead.
+## :bocs:
+## :section: 3
+## :heading: functions
+## :name: tmpdir
+##
+## Create a temporary directory. Similar to tempfile, but you'll get a directory
+## instead.
tmpdir() {
local dir
@@ -325,9 +351,14 @@ tmpdir() {
printf "%s" "$dir"
}
-# Create a temporary file. In usage, this is no different from mktemp itself,
-# however, it will apply additional checks to ensure everything is going
-# correctly, and the files will be cleaned up automatically at the end.
+## :bocs:
+## :section: 3
+## :heading: functions
+## :name: tmpfile
+##
+## Create a temporary file. In usage, this is no different from mktemp itself,
+## however, it will apply additional checks to ensure everything is going
+## correctly, and the files will be cleaned up automatically at the end.
tmpfile() {
local file