improve logging
This commit is contained in:
parent
1ed9278e92
commit
aadad1ea6b
36
orcli
36
orcli
|
@ -212,13 +212,6 @@ inspect_args() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# :command.user_lib
|
# :command.user_lib
|
||||||
# src/lib/error.sh
|
|
||||||
# log error message to STDERR
|
|
||||||
# shellcheck shell=bash
|
|
||||||
function error() {
|
|
||||||
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')]: ERROR $*"
|
|
||||||
}
|
|
||||||
|
|
||||||
# src/lib/get_csrf.sh
|
# src/lib/get_csrf.sh
|
||||||
# get CSRF token (introduced in OpenRefine 3.3)
|
# get CSRF token (introduced in OpenRefine 3.3)
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
@ -227,12 +220,10 @@ function get_csrf() {
|
||||||
if ! response="$(curl -fs "${OPENREFINE_URL}/command/core/get-csrf-token")"; then
|
if ! response="$(curl -fs "${OPENREFINE_URL}/command/core/get-csrf-token")"; then
|
||||||
if ! response="$(curl -fs "${OPENREFINE_URL}/command/core/get-version")"; then
|
if ! response="$(curl -fs "${OPENREFINE_URL}/command/core/get-version")"; then
|
||||||
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if ! [[ "${response}" == '{"token":"'* ]]; then
|
if ! [[ "${response}" == '{"token":"'* ]]; then
|
||||||
error "getting CSRF token failed!"
|
error "getting CSRF token failed!"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
echo "?csrf_token=$(echo "$response" | cut -d \" -f 4)"
|
echo "?csrf_token=$(echo "$response" | cut -d \" -f 4)"
|
||||||
fi
|
fi
|
||||||
|
@ -247,21 +238,32 @@ function get_id() {
|
||||||
local ids
|
local ids
|
||||||
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"; then
|
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"; then
|
||||||
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
if ! projects="$(echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"' | grep "${args[project]}")"; then
|
if ! projects="$(echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"' | grep ":${args[project]}$")"; then
|
||||||
error "project ${args[project]} not found"
|
error "project ${args[project]} not found"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
ids=$(echo "$projects" | cut -d : -f 1)
|
ids=$(echo "$projects" | cut -d : -f 1)
|
||||||
if ! [[ "${#ids}" == 13 ]]; then
|
if ! [[ "${#ids}" == 13 ]]; then
|
||||||
error "multiple projects found"
|
error "multiple projects found" "$projects"
|
||||||
echo >&2 "$projects"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
echo "$ids"
|
echo "$ids"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# src/lib/logging.sh
|
||||||
|
# print messages to STDERR
|
||||||
|
# shellcheck shell=bash
|
||||||
|
function error() {
|
||||||
|
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')] ERROR: $1"
|
||||||
|
shift
|
||||||
|
for msg in "$@"; do echo >&2 "$msg"; done
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
function log() {
|
||||||
|
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')] $1"
|
||||||
|
shift
|
||||||
|
for msg in "$@"; do echo >&2 "$msg"; done
|
||||||
|
}
|
||||||
|
|
||||||
# :command.command_functions
|
# :command.command_functions
|
||||||
# :command.function
|
# :command.function
|
||||||
orcli_info_command() {
|
orcli_info_command() {
|
||||||
|
@ -284,9 +286,13 @@ orcli_list_command() {
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"; then
|
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"; then
|
||||||
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
||||||
|
else
|
||||||
|
if [[ "${response}" == '{"projects":{}}' ]]; then
|
||||||
|
log "${OPENREFINE_URL} contains zero projects"
|
||||||
else
|
else
|
||||||
echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"'
|
echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"'
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# :command.parse_requirements
|
# :command.parse_requirements
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
# log error message to STDERR
|
|
||||||
# shellcheck shell=bash
|
|
||||||
function error() {
|
|
||||||
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')]: ERROR $*"
|
|
||||||
}
|
|
|
@ -5,12 +5,10 @@ function get_csrf() {
|
||||||
if ! response="$(curl -fs "${OPENREFINE_URL}/command/core/get-csrf-token")"; then
|
if ! response="$(curl -fs "${OPENREFINE_URL}/command/core/get-csrf-token")"; then
|
||||||
if ! response="$(curl -fs "${OPENREFINE_URL}/command/core/get-version")"; then
|
if ! response="$(curl -fs "${OPENREFINE_URL}/command/core/get-version")"; then
|
||||||
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if ! [[ "${response}" == '{"token":"'* ]]; then
|
if ! [[ "${response}" == '{"token":"'* ]]; then
|
||||||
error "getting CSRF token failed!"
|
error "getting CSRF token failed!"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
echo "?csrf_token=$(echo "$response" | cut -d \" -f 4)"
|
echo "?csrf_token=$(echo "$response" | cut -d \" -f 4)"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -6,17 +6,13 @@ function get_id() {
|
||||||
local ids
|
local ids
|
||||||
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"; then
|
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"; then
|
||||||
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
if ! projects="$(echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"' | grep "${args[project]}")"; then
|
if ! projects="$(echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"' | grep ":${args[project]}$")"; then
|
||||||
error "project ${args[project]} not found"
|
error "project ${args[project]} not found"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
ids=$(echo "$projects" | cut -d : -f 1)
|
ids=$(echo "$projects" | cut -d : -f 1)
|
||||||
if ! [[ "${#ids}" == 13 ]]; then
|
if ! [[ "${#ids}" == 13 ]]; then
|
||||||
error "multiple projects found"
|
error "multiple projects found" "$projects"
|
||||||
echo >&2 "$projects"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
echo "$ids"
|
echo "$ids"
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
# print messages to STDERR
|
||||||
|
# shellcheck shell=bash
|
||||||
|
function error() {
|
||||||
|
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')] ERROR: $1"
|
||||||
|
shift
|
||||||
|
for msg in "$@"; do echo >&2 "$msg"; done
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
function log() {
|
||||||
|
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')] $1"
|
||||||
|
shift
|
||||||
|
for msg in "$@"; do echo >&2 "$msg"; done
|
||||||
|
}
|
|
@ -2,6 +2,10 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"; then
|
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"; then
|
||||||
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
||||||
|
else
|
||||||
|
if [[ "${response}" == '{"projects":{}}' ]]; then
|
||||||
|
log "${OPENREFINE_URL} contains zero projects"
|
||||||
else
|
else
|
||||||
echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"'
|
echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"'
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue