-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelp
executable file
·77 lines (63 loc) · 2.08 KB
/
help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
__SOURCE__="${BASH_SOURCE[0]}"
while [[ -h "${__SOURCE__}" ]]; do
__SOURCE__="$(find "${__SOURCE__}" -type l -ls | sed -n 's@^.* -> \(.*\)@\1@p')"
done
__DIR__="$(cd -P "$(dirname "${__SOURCE__}")" && pwd)"
__NAME__="${__SOURCE__##*/}"
__AUTHOR__='S0AndS0'
__DESCRIPTION__='Prints help message and commands for more help'
## Provides 'failure'
source "${__DIR__}/shared_functions/modules/trap-failure/failure.sh"
trap 'failure "LINENO" "BASH_LINENO" "${BASH_COMMAND}" "${?}"' ERR
## Provides: argument_parser <arg-array-reference> <acceptable-arg-reference>
source "${__DIR__}/shared_functions/modules/argument-parser/argument-parser.sh"
## Provides: __license__ <description> <author>
source "${__DIR__}/shared_functions/license"
usage(){
local _message="${1}"
local _script_name="${_script_name:-${__NAME__}}"
_script_name="${_script_name##*/}"
_script_name="${_script_name##*..}"
local _script_path="${__DIR__}/${_script_name}"
if [[ "${_script_name}" == "${__NAME__}" ]]; then
cat <<EOF
## Usage
# ssh ${USER}@host-or-ip ${__NAME__} ${_script_name}
#
# ${__DESCRIPTION__}
#
# ${_script_name}
# Name of script to run "--help" with
#
# -l --license
# Shows script or project license then exits
#
# -h --help help
# Displays this message and exits
EOF
elif [ -f "${_script_path}" ] && [ -e "${_script_path}" ]; then
printf '%s --help' "${_script_name}"
"${_script_path}" --help
local _exit_status="${?}"
else
printf 'Error finding help for %s\n' "${_script_name}" >&2
local _exit_status="1"
fi
(("${#_message}")) && [[ "${_message}" != '0' ]] && {
printf >&2 'Error - %s\n' "${_message}"
}
return "${_exit_status}"
}
_args=("${@:?# No arguments provided try: ${__NAME__} help}")
_valid_args=('--help|-h|help:bool'
'--license|-l|license:bool'
'--script-name:posix-nil')
argument_parser '_args' '_valid_args'
_exit_status="${?}"
((_license)) && {
__license__ "${__DESCRIPTION__}" "${__AUTHOR__}"
exit 0
}
usage "${_exit_status}"
exit "${_exit_status}"