-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestions.bash
executable file
·85 lines (70 loc) · 2.04 KB
/
questions.bash
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
#!/bin/bash
# Copyright 2020 Liudng. All rights reserved.
# Use of this source code is governed by Apache License
# that can be found in the LICENSE file.
# trace ERR through pipes
set -o pipefail
# set -e : exit the script if any statement returns a non-true return value
set -o errexit
# The dev package version
declare -gr dev_global_version="1.0.0"
# The dev execution file path
declare -gr dev_global_self="$(realpath $0)"
# The dev execution base path
declare -gr dev_global_base="$(dirname $(dirname $dev_global_self))"
cmd_body() {
#
# Write your code here.
#
echo "This is a sample bash script."
echo "Custom arguments: $@"
while read -r line; do
echo $line
done <<< "$(apropos -s 1 .)"
}
dev_kernel_help_usage() {
echo "Usage: $(basename $dev_global_self) [--trace] [--verbose] [custom-arguments...]"
echo " $(basename $dev_global_self) [--help] [--version]"
echo ""
echo "Optional arguments:"
echo " --help Help topic and usage information"
echo " --trace Print command traces before executing command"
echo " --verbose Produce more output about what the program does"
echo " --version Output version information and exit"
#
# Append your custom help here.
#
}
dev_kernel_optional_arguments() {
case "$1" in
--help)
dev_kernel_help_usage
exit 0
;;
--version)
echo "$dev_global_version" >&2
exit 0
;;
--trace)
declare -gr dev_global_trace="1"
;;
--verbose)
declare -gr dev_global_verbose="1"
;;
#
# Add your custom optional arguments here.
#
*)
echo "Optional argument not found: $1" >&2
;;
esac
}
dev_main() {
while [[ $# -gt 0 && "${1:0:1}" == "-" ]]; do
dev_kernel_optional_arguments "$1"
shift
done
[[ "$dev_global_trace" -eq "1" ]] && set -o xtrace
cmd_body $@
}
dev_main $@