-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_DeleteRemoteRepoIfEmpty_utils.sh
97 lines (84 loc) · 3.43 KB
/
04_DeleteRemoteRepoIfEmpty_utils.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
#!/bin/bash
# #############################################
# The MIT License (MIT)
#
# Copyright © 2020 Michael Czapski
# #############################################
[[ ${libSourceMgmt} ]] || source ./libs/libSourceMgmt.sh "1.0.0"
[[ ${__env_GlobalConstants} ]] || source ./utils/__env_GlobalConstants.sh "1.0.0" || exit ${__FAILED}
declare -u _04_DeleteRemoteRepoIfEmpty_utils="1.0.0"
fn__SourcedVersionOK "${0}" "${LINENO}" "${1:-0.0.0}" "${_04_DeleteRemoteRepoIfEmpty_utils}" || exit ${__FAILED}
[[ ${fn__UtilityGeneric} ]] || { source ./utils/fn__UtilityGeneric.sh "1.0.1" || exit ${__FAILED}; }
:<<-'------------Function_Usage_Note-------------------------------'
Usage:
fn__ForceRemoveRemoteRepo \
"${*}"
Returns:
${__EXECUTION_ERROR}
${__NO} if command line argument is not provided or it's value does not match the expectation
${__YES} if command line argument is provided and matches the expectation
Example:
fn__ForceRemoveRemoteRepo "${*}" && echo "Yes, force" || echo "No, don't force"
------------Function_Usage_Note-------------------------------
fn__ForceRemoveRemoteRepo() {
local -r prCmdArguments="${1}"
local -r lrOptionValue=":f:" # provide a single option, possible prefixed with : and possibly suffixed with : if option value is required
local lOutputString=""
fn__GetOptionValue "${lrOptionValue}" "${prCmdArguments}" "lOutputString" && STS=${?} || STS=${?}
case ${STS} in
${__EXECUTION_ERROR} | ${__EMPTY_ARGUMENT_NOT_ALLOWED})
echo "Execution error - check logic" >&2
return ${__EXECUTION_ERROR};
;;
${__NO})
return ${__NO}
;;
*)
# only want the first letter of the string following the -f flag
# and only care aboiut Y - everything else is a ${__NO}
local -r _OPT_VAL_=${lOutputString^^}
[[ "${_OPT_VAL_:0:1}" == "Y" ]] \
&& return ${__YES} \
|| return ${__NO}
;;
esac
}
:<<-'------------Function_Usage_Note-------------------------------'
Usage:
fn__InputIsValid
"${pClientGitRemoteRepoName}"
${pCanonicalClientGitRemoteRepoName}
${pGiterverRemoteRepoNameMaxLen}
Returns:
${__DONE}
${__FAILED}
------------Function_Usage_Note-------------------------------
function fn__InputIsValid() {
local -r lUsage='
Usage:
fn__InputIsValid
"${pClientGitRemoteRepoName}"
${pCanonicalClientGitRemoteRepoName}
${pGiterverRemoteRepoNameMaxLen}
&& STS=${__DONE}
|| STS=${__FAILED}
'
[[ $# -lt 3 || "${0^^}" == "HELP" ]] && {
echo -e "____ Insufficient number of arguments $@\n${lUsage}"
return ${__FAILED}
}
local -r pClientGitRemoteRepoName=${1?"${lUsage}"}
local -r pCanonicalClientGitRemoteRepoName=${2?"${lUsage}"}
local -r pGiterverRemoteRepoNameMaxLen=${3?"${lUsage}"}
[[ ${#pCanonicalClientGitRemoteRepoName} -lt 2 ]] && {
echo "____ Git repository name '${pClientGitRemoteRepoName}' translated to '${pCanonicalClientGitRemoteRepoName}'"
echo "____ Git repository name must be at least 2 characters long"
return ${__FAILED}
}
[[ ${#pCanonicalClientGitRemoteRepoName} -gt ${pGiterverRemoteRepoNameMaxLen} ]] && {
echo "____ Final Git repository name '${pCanonicalClientGitRemoteRepoName}' is longer than the maximum of ${pGiterverRemoteRepoNameMaxLen} characters"
echo "____ Git repository name must be no longer than ${pGiterverRemoteRepoNameMaxLen} characters"
return ${__FAILED}
}
return ${__DONE}
}