orcli/src/lib/get_id.sh

19 lines
632 B
Bash
Raw Normal View History

2022-03-25 11:16:02 +01:00
# get project id (derived from project name if needed)
2022-04-14 12:06:54 +02:00
# shellcheck shell=bash
2022-03-25 23:02:28 +01:00
function get_id() {
local response
local projects
local ids
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"; then
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
fi
2022-04-14 12:06:54 +02:00
if ! projects="$(echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"' | grep -e ":$1$" -e "^$1:")"; then
error "project $1 not found"
2022-03-25 23:02:28 +01:00
fi
ids=$(echo "$projects" | cut -d : -f 1)
if ! [[ "${#ids}" == 13 ]]; then
2022-04-12 18:26:43 +02:00
error "multiple projects found" "$projects"
2022-03-25 23:02:28 +01:00
fi
echo "$ids"
2022-03-25 11:16:02 +01:00
}