-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.sh
executable file
·98 lines (76 loc) · 2.17 KB
/
command.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
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
#!/bin/bash
set -e
set -u
ENV=local
PARAMETER=
BASE_DIR=$(dirname $0)
SCRIPT_PATH="$( cd "${BASE_DIR}" && pwd -P )"
load_env(){
ENV_FILE="${SCRIPT_PATH}/env/${ENV}.env"
if test -f "${ENV_FILE}"; then
source "${ENV_FILE}"
fi
}
load_env
exit_err() {
echo "ERROR: ${1}" >&2
exit 1
}
# Usage: -h, --help
# Description: Show help text
option_help() {
printf "Usage: %s [options...] COMMAND <parameter> \n\n" "${0}"
printf "Default command: --help\n\n"
echo "Options:"
grep -e '^[[:space:]]*# Usage:' -e '^[[:space:]]*# Description:' -e '^option_.*()[[:space:]]*{' "${0}" | while read -r usage; read -r description; read -r option; do
if [[ ! "${usage}" =~ Usage ]] || [[ ! "${description}" =~ Description ]] || [[ ! "${option}" =~ ^option_ ]]; then
exit_err "Error generating help text."
fi
printf " %-32s %s\n" "${usage##"# Usage: "}" "${description##"# Description: "}"
done
printf "\n"
echo "Commands:"
grep -e '^[[:space:]]*# Command Usage:' -e '^[[:space:]]*# Command Description:' -e '^command_.*()[[:space:]]*{' "${0}" | while read -r usage; read -r description; read -r command; do
if [[ ! "${usage}" =~ Usage ]] || [[ ! "${description}" =~ Description ]] || [[ ! "${command}" =~ ^command_ ]]; then
exit_err "Error generating help text."
fi
printf " %-32s %s\n" "${usage##"# Command Usage: "}" "${description##"# Command Description: "}"
done
}
# Command Usage: tag
# Command Description: Git release with version
command_tag() {
git tag ${PARAMETER} && git push origin ${PARAMETER}
}
check_msg() {
printf "\xE2\x9C\x94 ${1}\n"
}
main() {
[[ -z "${@}" ]] && eval set -- "--help"
local theCommand=
set_command() {
[[ -z "${theCommand}" ]] || exit_err "Only one command at a time!"
theCommand="${1}"
}
while (( ${#} )); do
case "${1}" in
--help|-h)
option_help
exit 0
;;
tag|test|coverage|bump|rn)
set_command "${1}"
;;
*)
PARAMETER="${1}"
;;
esac
shift 1
done
[[ ! -z "${theCommand}" ]] || exit_err "Command not found!"
case "${theCommand}" in
tag) command_tag;;
*) option_help; exit 1;;
esac
}
main "${@-}"