using env variables for TOKEN, USER and EMAIL
This commit is contained in:
parent
845f0b00e1
commit
f06d537ffb
26
rtenets
26
rtenets
|
@ -63,6 +63,23 @@ enter() {
|
|||
printf "${input_var}"
|
||||
}
|
||||
|
||||
# Test if a variable name is set
|
||||
is_set() {
|
||||
local var_name="$1"
|
||||
eval "! [[ -z \"\${${var_name}+x}\" ]]"
|
||||
return $?
|
||||
}
|
||||
|
||||
# Set var to first value if unset
|
||||
alt_var() {
|
||||
local value_if_unset="$1"
|
||||
local variable="$2"
|
||||
if is_set "${variable}"; then
|
||||
printf "%s" "$(eval "printf \"%s\" \"\${${variable}}\"")"
|
||||
else
|
||||
printf "%s" "$value_if_unset"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check that command exists
|
||||
has_command() {
|
||||
|
@ -88,13 +105,13 @@ get_gitea_token(){
|
|||
TOKEN="$(enter "gitea token: ")"
|
||||
fi
|
||||
readonly TOKEN
|
||||
info "gitea token: '${TOKEN}'"
|
||||
}
|
||||
|
||||
gitea() {
|
||||
check_api_prerequisites
|
||||
readonly TOKEN
|
||||
|
||||
if [[ -z ${TOKEN+x} ]]; then
|
||||
if ! is_set TOKEN; then
|
||||
get_gitea_token
|
||||
fi
|
||||
|
||||
|
@ -136,8 +153,8 @@ check_git_config() {
|
|||
error "git not found, please install"
|
||||
fi
|
||||
|
||||
readonly USER="$(get_git_config user.name)"
|
||||
readonly EMAIL="$(get_git_config user.email)"
|
||||
readonly USER="$(alt_var "$(get_git_config user.name)" USER)"
|
||||
readonly EMAIL="$(alt_var "$(get_git_config user.email)" EMAIL)"
|
||||
info "found git credentials:\\n - user.name: '${USER}'\\n - user.email: '${EMAIL}'"
|
||||
}
|
||||
|
||||
|
@ -260,7 +277,6 @@ main() {
|
|||
check_git_config
|
||||
create_tenet_file_tree
|
||||
|
||||
get_gitea_token
|
||||
gitea /user GET
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue