-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneral
More file actions
113 lines (90 loc) · 2.99 KB
/
general
File metadata and controls
113 lines (90 loc) · 2.99 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Copyright (c) 2025 Richard Bloch
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# -----------------------------------------------------------------------------
#
# Bash library (bash-lib) for general-purpose script processing
# Version: 1.1.0
#
# -----------------------------------------------------------------------------
# check_program_dependencies() checks external program dependencies passed in
# through $0
#
check_program_dependencies() {
for dep in "$@"; do
if ! command -v "$dep" &>/dev/null; then
printf "Error: program '%s' not installed.\n" "$dep" >&2
quit 1
fi
done
}
# -----------------------------------------------------------------------------
# check_file_dependencies() checks file dependencies passed in through $0
#
check_file_dependencies() {
for file in "$@"; do
if [[ ! -f "$file" ]]; then
printf "Error: file '%s' not found.\n" "$file" >&2
quit 1
fi
done
}
# -----------------------------------------------------------------------------
# display_banner() builds and displays a custom-sized script banner using
# configuration details managed through the args library
#
display_banner() {
cat <<-EOF
|
| $(get_config_details title)
| $(get_config_details version)
|
| Usage:
| $(get_config_details syntax)
|
EOF
local max_col=0
local arg_count
arg_count=$(get_config_args_length)
# Determine the maximum width needed for the arguments column for alignment
for ((i = 0; i < arg_count; i++)); do
local arg_string
arg_string="$(get_config_arg "$i" short_form), $(get_config_arg "$i" long_form)"
((${#arg_string} > max_col)) && max_col=${#arg_string}
done
# Print the formatted arguments
for ((i = 0; i < arg_count; i++)); do
local arg
local desc
arg="$(get_config_arg "$i" short_form), $(get_config_arg "$i" long_form)"
desc="$(get_config_arg "$i" description)"
printf " | %-*s %s\n" "$max_col" "$arg" "$desc"
done
printf " |\n\n"
}
# -----------------------------------------------------------------------------
# function exist_directory() confirms directory existence
#
exist_directory() {
if [[ ! -d "$1" ]]; then
printf "Error: directory '%s' not found.\n" "$1" >&2
quit 1
fi
}
# -----------------------------------------------------------------------------
# quit() exits program (with exit status passed in)
#
quit() {
exit "${1:-1}"
}