Skip to content

Commit 968ecdc

Browse files
committed
Separating usage from help
Signed-off-by: Sebastian Franz <sebastian.franz@iteratec.com>
1 parent 8def6d8 commit 968ecdc

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

‎bin/install.sh‎

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Creates namespace, securecodebox-system, and installs the operator.
66
# Then installs all possible resources (scanners, demo-apps, hooks).
77
#
8-
# There exist two modes:
8+
# There exist different modes:
99
# Call without parameters to install interactively
1010
# Call with --all to install all available resources automatically
1111
# Call with --scanners / --demo-apps / --hooks to only install the wanted resources
@@ -16,6 +16,8 @@
1616
set -euo pipefail
1717
shopt -s extglob
1818

19+
USAGE="Usage: $(basename "$0") [--all] [--scanners] [--hooks] [--demo-apps] [--help|-h]"
20+
1921
COLOR_HIGHLIGHT="\e[35m"
2022
COLOR_OK="\e[32m"
2123
COLOR_ERROR="\e[31m"
@@ -45,12 +47,10 @@ function print() {
4547
fi
4648
}
4749

48-
# TODO: Separate usage from help.
49-
function usage() {
50-
local usage
51-
usage="Usage: $(basename "$0") [--all] [--scanners] [--hooks] [--demo-apps] [--help|-h]"
50+
function printHelp() {
5251
local help
5352
help=$(cat <<- EOT
53+
$USAGE
5454
The installation is interactive if no arguments are provided.
5555
5656
Options
@@ -66,13 +66,9 @@ Examples:
6666
install.sh --all Installs the operator in namespace: securecodebox-system and
6767
all resources in namespace: default
6868
69-
install.sh --hooks --scanners
70-
Installs only operator, scanners and hooks
69+
install.sh --hooks --scanners Installs only operator, scanners and hooks
7170
EOT
7271
)
73-
print "SecureCodeBox Install Script"
74-
print "$usage"
75-
print
7672
print "$help"
7773
}
7874

@@ -211,8 +207,6 @@ function interactiveInstall() {
211207
}
212208

213209
function unattendedInstall() {
214-
215-
216210
if [[ $INSTALL_SCANNERS == true ]]; then
217211
print "Starting to install scanners..."
218212
installResources "$BASE_DIR/scanners" "default" True
@@ -258,12 +252,12 @@ function parseArguments() {
258252
shift
259253
;;
260254
-h|--help)
261-
usage
255+
printHelp
262256
exit
263257
;;
264258
--*) # unsupported flags
265259
print "Error: Unsupported flag $1" >&2
266-
usage
260+
print "$USAGE"
267261
exit 1
268262
;;
269263
*) # preserve positional arguments
@@ -273,6 +267,9 @@ function parseArguments() {
273267
done
274268
}
275269

270+
# Main Script:
271+
parseArguments "$@"
272+
276273
print "$COLOR_HIGHLIGHT" " "
277274
print "$COLOR_HIGHLIGHT" " _____ _ ____ "
278275
print "$COLOR_HIGHLIGHT" " / ____| | | | _ \ "
@@ -282,8 +279,6 @@ print "$COLOR_HIGHLIGHT" " \__ \ __/ (__| |_| | | | __/ |___| (_) | (_| | __/
282279
print "$COLOR_HIGHLIGHT" " |___/\___|\___|\__,_|_| \___|\_____\___/ \__,_|\___|____/ \___/_/\_\ "
283280
print "$COLOR_HIGHLIGHT" " "
284281

285-
286-
parseArguments "$@"
287282
if [[ $INSTALL_INTERACTIVE == true ]]; then
288283
welcomeToInteractiveInstall
289284
fi

0 commit comments

Comments
 (0)