-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhello-world
executable file
·81 lines (68 loc) · 1.95 KB
/
hello-world
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
#!/bin/bash
# Copyright (C) 2017-2022 Andrei Pavel, [email protected]
# Licensed under the MIT License
# Header
script_path="$(dirname "$(readlink -f "${0}")")"
. "${script_path}/lib/header"
. "${script_path}/lib/utils"
. "${script_path}/lib/spinner"
. "${script_path}/lib/traps"
argument 'simple' 'approval_required' '-a|--approval' 'whether to ask user for approval'
argument 'valued' 'count' '-n' 'print $count times'
argument 'valued' 'yaml' '-y' 'specify path to the configuration file'
argument 'positional' 'string' 'something other than "Hello, world!" to print'
parse-parameters "${@}"
set -- "${EXTRA_PARAMETERS[@]}"
mandatory count
# Default parameters
test -z "${approval_required+x}" && approval_required=false
test -z "${string+x}" && string="Hello, world!"
#------------------------------------------------------------------------------#
# Approval?
if ${approval_required} && ! confirm; then
exit 0
fi
# Print.
enable-verbose
if test -n "${yaml+x}"; then
mandatory-command yq
start-spinner "Printing entries from ${yaml}..."
for (( i = 0; i < count; ++i )); do
yq -r '.data | to_entries | map(select(.value != null) | "\(.key) \(.value)") | .[]' < "${yaml}"
done
stop-spinner ${?}
else
start-spinner 'Printing...'
for (( i = 0; i < count; ++i )); do
printf '%s\n' "${string}"
done
stop-spinner ${?}
fi
if test -n "${this+x}"; then
printf 'this %s\n' "${this}"
fi
if test -n "${list+x}"; then
printf 'list: ( '
for i in $(seq 0 $(( ${#list[@]} - 1 ))); do
printf '%s ' "${list[${i}]}"
done
printf ')\n'
fi
# Show off spinners.
start-spinner 'Nested spinners disable the inner ones...'
start-spinner 'This one...'
start-spinner 'And this one...'
sleep 1
stop-spinner 0
stop-spinner 0
start-spinner 'And this one...'
sleep 1
stop-spinner 0
stop-spinner 0
disable-spinners
stop-spinner 0
stop-spinner 0
start-spinner 'Go crazy here!'
start-spinner 'Even order doesn''t count.'
start-spinner 'Spinners are off.'
enable-spinners