-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.sh
executable file
·56 lines (43 loc) · 1.02 KB
/
demo.sh
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
#!/usr/bin/env bash
set -e
source ./lib/verbose-module
verbose=false
# Parse options
while [[ "$#" -gt 0 ]]; do
case "$1" in
-v|--verbose)
verbose=true
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
shift
done
# Set verbosity mode
if [ "$verbose" = "true" ]; then
enable_verbose_mode
else
disable_verbose_mode
fi
# Make some noise...
# This should always print to the screen since it's using our special "shout" method.
shout "Begin."
# This should always print "foo: 55"
foo="$(echo "55")"
shout "foo: $foo"
# This should only print in verbose mode since it's a normal 'echo'.
echo "Hello from echo!"
# deprecated_method:
# Echo's out a message to stderr, but still returns
# a "happy" exit code. The warning should only display
# when verbose mode is set.
function deprecated_method() {
>&2 echo "WARN: this method is deprecated"
return 0
}
# This method should only print its deprecation warning when in verbose mode.
deprecated_method
# done.
shout "Finished."