1- #! /bin/bash
1+ #! /usr/ bin/env bash
22set -euo pipefail
33
44
55# # --- Base --- ##
6- # Getting path of this script file:
7- _SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null 2>&1 && pwd) "
6+ _SCRIPT_DIR=" $( cd -- " $( dirname -- " ${BASH_SOURCE[0]:- " $0 " } " ) " > /dev/null 2>&1 && pwd -P) "
87_PROJECT_DIR=" $( cd " ${_SCRIPT_DIR} /.." > /dev/null 2>&1 && pwd) "
98cd " ${_PROJECT_DIR} " || exit 2
109
1110
12- # Loading .env file (if exists):
13- if [ -f " .env" ]; then
14- # shellcheck disable=SC1091
15- source .env
11+ # shellcheck disable=SC1091
12+ [ -f .env ] && . .env
13+
14+
15+ if [ ! -f ./scripts/get-version.sh ]; then
16+ echo " [ERROR]: 'get-version.sh' script not found!" >&2
17+ exit 1
1618fi
1719# # --- Base --- ##
1820
@@ -31,54 +33,75 @@ _IS_PUSH=false
3133# # --- Variables --- ##
3234
3335
34- # # --- Main --- ##
35- main ()
36- {
37- # # --- Menu arguments --- ##
38- if [ -n " ${1:- } " ]; then
39- local _input
40- for _input in " ${@:- } " ; do
41- case ${_input} in
42- -b=* | --bump-type=* )
43- _BUMP_TYPE=" ${_input#* =} "
44- shift ;;
45- -c | --commit)
46- _IS_COMMIT=true
47- shift ;;
48- -t | --tag)
49- _IS_TAG=true
50- shift ;;
51- -p | --push)
52- _IS_PUSH=true
53- shift ;;
54- * )
55- echo " [ERROR]: Failed to parsing input -> ${_input} !"
56- echo " [INFO]: USAGE: ${0} -b=*, --bump-type=* [major | minor | patch] | -c, --commit | -t, --tag | -p, --push"
57- exit 1;;
58- esac
59- done
60- fi
61- # # --- Menu arguments --- ##
36+ # # --- Menu arguments --- ##
37+ _usage_help () {
38+ cat << EOF
39+ USAGE: ${0} [options]
6240
41+ OPTIONS:
42+ -b, --bump-type [TYPE] Specify version bump type. [major | minor | patch]
43+ -c, --commit Create a commit for the bumped version. Default: false
44+ -t, --tag Create a git tag for the bumped version. Default: false
45+ -p, --push Push commits and tags to the remote. Default: false
46+ -h, --help Show this help message.
6347
64- if [ -z " ${_BUMP_TYPE:- } " ]; then
65- echo " [ERROR]: Bump type is empty, use '-b=' or '--bump-type=' argument!"
66- exit 1
67- fi
48+ EXAMPLES:
49+ ${0} -b patch -c -t -p
50+ ${0} --bump-type=minor
51+ EOF
52+ }
6853
69- if [ " ${_BUMP_TYPE} " != " major" ] && [ " ${_BUMP_TYPE} " != " minor" ] && [ " ${_BUMP_TYPE} " != " patch" ]; then
70- echo " [ERROR]: Bump type '${_BUMP_TYPE} ' is invalid, should be: 'major', 'minor' or 'patch'!"
71- exit 1
72- fi
54+ while [ $# -gt 0 ]; do
55+ case " ${1} " in
56+ -b | --bump-type)
57+ [ $# -ge 2 ] || { echo " [ERROR]: ${1} requires a value!" >&2 ; exit 1; }
58+ _BUMP_TYPE=" ${2} "
59+ shift 2;;
60+ -b=* | --bump-type=* )
61+ _BUMP_TYPE=" ${1#* =} "
62+ shift ;;
63+ -c | --commit)
64+ _IS_COMMIT=true
65+ shift ;;
66+ -t | --tag)
67+ _IS_TAG=true
68+ shift ;;
69+ -p | --push)
70+ _IS_PUSH=true
71+ shift ;;
72+ -h | --help)
73+ _usage_help
74+ exit 0;;
75+ * )
76+ echo " [ERROR]: Failed to parse argument -> ${1} !" >&2
77+ _usage_help
78+ exit 1;;
79+ esac
80+ done
81+ # # --- Menu arguments --- ##
82+
83+
84+ if [ -z " ${_BUMP_TYPE:- } " ]; then
85+ echo " [ERROR]: Bump type is empty, use '-b=' or '--bump-type=' argument!"
86+ exit 1
87+ fi
7388
74- if [ " ${_IS_COMMIT} " == true ]; then
75- if [ -z " $( which git) " ]; then
76- echo " [ERROR]: 'git' not found or not installed!"
77- exit 1
78- fi
89+ if [ " ${_BUMP_TYPE} " != " major" ] && [ " ${_BUMP_TYPE} " != " minor" ] && [ " ${_BUMP_TYPE} " != " patch" ]; then
90+ echo " [ERROR]: Bump type '${_BUMP_TYPE} ' is invalid, should be: 'major', 'minor' or 'patch'!"
91+ exit 1
92+ fi
93+
94+ if [ " ${_IS_COMMIT} " == true ]; then
95+ if ! command -v git > /dev/null 2>&1 ; then
96+ echo " [ERROR]: Not found 'git' command, please install it first!" >&2
97+ exit 1
7998 fi
99+ fi
80100
81101
102+ # # --- Main --- ##
103+ main ()
104+ {
82105 echo " [INFO]: Checking current version..."
83106 local _current_version
84107 _current_version=" $( ./scripts/get-version.sh) "
@@ -135,5 +158,5 @@ main()
135158 fi
136159}
137160
138- main " ${ @:- } "
161+ main
139162# # --- Main --- ##
0 commit comments