|
1 |
| -# vim: set ft=sh syn=bash : |
| 1 | +# vim: set ft=sh syn=bash cc=160 : |
2 | 2 | # shellcheck shell=bash
|
3 | 3 |
|
4 | 4 | #
|
5 |
| -# Copyright (C) 2022 Chris 'sh0shin' Frage |
| 5 | +# Copyright (C) 2022-2023 Chris 'sh0shin' Frage |
6 | 6 | #
|
7 | 7 | # This program is free software: you can redistribute it and/or modify
|
8 | 8 | # it under the terms of the GNU Affero General Public License, version 3,
|
|
17 | 17 | # along with this program. If not, see <https://www.gnu.org/licenses/>.
|
18 | 18 | #
|
19 | 19 |
|
20 |
| -# duct-skeletor |
21 |
| -# Hello, Skeletor here! Example Skeleton for duct plugins. |
| 20 | +# @plug duct-skeletor # ; Plugin name (same as filename). |
| 21 | +# @desc Hello, Skeletor here! # ; Plugin description. |
22 | 22 |
|
23 |
| -# skeletor |
| 23 | +# @pvar Plugin global variable. |
| 24 | +declare -g DUCT_SKELETOR_GLOBAL="${DUCT_SKELETOR_GLOBAL:-}" # ; Global plugin variable. |
24 | 25 |
|
25 |
| -# Skeletor options (defaults). |
26 |
| -declare -r -a _DUCT_SKELETOR_OPTIONS=( |
27 |
| - --foo |
28 |
| - --bar |
29 |
| -) |
| 26 | +# @func duct skeletor say # ; Function name (without `__` & `_`) |
| 27 | + |
| 28 | +# @fvar Skeletor say options (defaults.) # ; Function variable description. |
| 29 | +declare -r -a _DUCT_SKELETOR_SAY_OPTIONS=() # ; Readonly array defaults and internals. |
30 | 30 |
|
31 |
| -# Skeletor list (defaults). |
32 |
| -declare -r -a _DUCT_SKELETOR_LIST=() |
| 31 | +# @fvar Skeletor say binary. |
| 32 | +declare -g DUCT_SKELETOR_SAY_BINARY="${DUCT_SKELETOR_SAY_BINARY:-"say"}" # ; Use long names for option variables. |
| 33 | + # ; Setting a sane default. |
| 34 | +# @fvar Skeletor say string. |
| 35 | +declare -g DUCT_SKELETOR_SAY_MESSAGE="${DUCT_SKELETOR_SAY_MESSAGE:-"Hello, Skeletor here!"}" |
33 | 36 |
|
34 |
| -# Skeletor options. |
35 |
| -declare -g -a DUCT_SKELETOR_OPTIONS=( "${DUCT_SKELETOR_OPTIONS[@]:-${_DUCT_SKELETOR_OPTIONS[@]}}" ) |
| 37 | +# @fvar Skeletor say voice. |
| 38 | +declare -g DUCT_SKELETOR_SAY_VOICE="${DUCT_SKELETOR_SAY_VOICE:-"Albert"}" |
36 | 39 |
|
37 |
| -# shellcheck disable=SC2206 |
38 |
| -# Skeleter list. |
39 |
| -declare -g -a DUCT_SKELETOR_LIST=( ${DUCT_SKELETOR_LIST[@]:-${_DUCT_SKELETOR_LIST[@]}} ) |
| 40 | +# shellcheck disable=SC2206 # ; Disable quote check for empty array defaults! |
| 41 | +# @fvar Skeletor say options. |
| 42 | +declare -g -a DUCT_SKELETOR_SAY_OPTIONS=( ${DUCT_SKELETOR_SAY_OPTIONS[@]:-${_DUCT_SKELETOR_SAY_OPTIONS[@]}} ) # ; Don't quote empty array defaults! |
40 | 43 |
|
41 |
| -# Skeletor other. |
42 |
| -declare -g DUCT_SKELETOR_OTHER="${DUCT_SKELETOR_OTHER:-}" |
| 44 | +# @desc Let skeletor say. # ; Function description. |
| 45 | +# @intl false # ; Internal function only? |
| 46 | +# @life skeletor # ; Lifetime for deprecation etc. |
| 47 | +# @deps duct-msg duct-run # ; Plugin dependencies. |
| 48 | +# @opts [string] # ; Optional options use `[]`, required use `<>`. |
| 49 | +__duct_skeletor_say() { |
| 50 | + local SKELETOR_SAY_MSG="${1:-${DUCT_SKELETOR_SAY_MESSAGE}}" # ; Declare all function variables as local! |
| 51 | + # ; Short names are allowed within the function. |
| 52 | + local -a SKELETOR_SAY_OPTS=( |
| 53 | + --voice="$DUCT_SKELETOR_SAY_VOICE" |
| 54 | + "${DUCT_SKELETOR_SAY_OPTIONS[@]}" |
| 55 | + ) |
| 56 | + |
| 57 | + __duct_run "$DUCT_SKELETOR_SAY_BINARY" "${SKELETOR_SAY_OPTS[@]}" "$SKELETOR_SAY_MSG" # ; Use `__duct_run` to execute commands. |
| 58 | +} |
| 59 | + |
| 60 | +# @func duct skeletor load # ; Loader function (called by `duct-plug`) . |
| 61 | + |
| 62 | +# @fvar List of skeletor requirements (readonly). |
| 63 | +declare -r -a _DUCT_SKELETOR_LOAD_REQUIREMENTS=( |
| 64 | + "$DUCT_SKELETOR_SAY_BINARY" # ; Inherit required binaries. |
| 65 | +) |
43 | 66 |
|
44 |
| -# Skeletor number. |
45 |
| -declare -g -i DUCT_SKELETOR_NUMBER="${DUCT_SKELETOR_NUMBER:-540}" |
| 67 | +# @desc Check for duct-skeletor requirements. |
| 68 | +# @intl true # ; Internal function! |
| 69 | +# @life skeletor |
| 70 | +# @deps duct-msg |
| 71 | +# @opts |
| 72 | +__duct_skeletor_load() { |
| 73 | + __duct_intl # ; Run `__duct_intl` to avoid external calls! |
46 | 74 |
|
47 |
| -# deps: duct-msg |
48 |
| -# intl: false |
49 |
| -# life: skeletor |
50 |
| -# desc: Skeletor function description. |
51 |
| -# opts: <skeletor> |
52 |
| -__duct_skeletor() { |
53 |
| - local SKELETOR="${1:-}" |
54 |
| - shift |
55 |
| - local OPTS=( "$@" ) |
| 75 | + local SKELETOR_LOAD_RC=0 |
56 | 76 |
|
57 |
| - if [[ -z "$SKELETOR" ]] |
58 |
| - then |
59 |
| - __duct_msg e "Skeletor error!" |
60 |
| - return 1 |
61 |
| - fi |
| 77 | + __duct_bin_check "${_DUCT_SKELETOR_LOAD_REQUIREMENTS[@]}" || SKELETOR_LOAD_RC=$? # ; Check requirements. |
62 | 78 |
|
63 |
| - __duct_msg n "Hello, $SKELETOR here! (${OPTS[*]})" |
| 79 | + return $SKELETOR_LOAD_RC |
64 | 80 | }
|
65 |
| -readonly -f __duct_skeletor |
|
0 commit comments