add delete --force

This commit is contained in:
felixlohmeier 2022-12-13 11:05:18 +00:00
parent 748137e15a
commit e59f0f8941
6 changed files with 47 additions and 18 deletions

35
orcli
View File

@ -144,6 +144,11 @@ orcli_delete_usage() {
echo echo
# :command.usage_flags # :command.usage_flags
# :flag.usage
echo " --force, -f"
printf " delete all projects with the same name\n"
echo
# :flag.usage # :flag.usage
echo " --quiet, -q" echo " --quiet, -q"
printf " suppress log output, print errors only\n" printf " suppress log output, print errors only\n"
@ -728,22 +733,22 @@ function get_csrf() {
# get project id (derived from project name if needed) # get project id (derived from project name if needed)
# shellcheck shell=bash # shellcheck shell=bash
function get_id() { function get_id() {
local response projects ids local response projects projectid
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}"
fi fi
if ! projects="$(echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"' | grep -e ":$1$" -e "^$1:")"; then if ! projects="$(echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"' | grep -e ":$1$" -e "^$1:")"; then
error "project $1 not found" error "project $1 not found"
fi fi
ids=$(echo "$projects" | cut -d : -f 1) projectid=$(echo "$projects" | cut -d : -f 1)
if ! [[ "${#ids}" == 13 ]]; then if ! [[ "${#projectid}" == 13 ]]; then
error "multiple projects found" "$projects" error "multiple projects found" "$projects"
fi fi
echo "$ids" echo "$projectid"
} }
function get_ids() { function get_ids() {
local response projects ids local response projects
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}"
fi fi
@ -954,7 +959,7 @@ send_completions() {
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'delete\'*)' echo $' \'delete\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --quiet -h -q")" -- "$cur" )' echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--force --help --quiet -f -h -q")" -- "$cur" )'
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'import\'*)' echo $' \'import\'*)'
@ -1008,10 +1013,14 @@ orcli_delete_command() {
# src/delete_command.sh # src/delete_command.sh
# shellcheck shell=bash disable=SC2154 # shellcheck shell=bash disable=SC2154
# get project ids # get project id(s)
projectids="$(get_ids "${args[project]}")" if [[ ${args[--force]} ]]; then
projectids="$(get_ids "${args[project]}")"
else
projectids="$(get_id "${args[project]}")"
fi
# loop over multiple project ids # loop over one or more project ids
for projectid in ${projectids}; do for projectid in ${projectids}; do
# get csrf token and post data # get csrf token and post data
if response="$(curl -fs --data "project=${projectid}" "${OPENREFINE_URL}/command/core/delete-project$(get_csrf)")"; then if response="$(curl -fs --data "project=${projectid}" "${OPENREFINE_URL}/command/core/delete-project$(get_csrf)")"; then
@ -1679,6 +1688,14 @@ orcli_delete_parse_requirements() {
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
key="$1" key="$1"
case "$key" in case "$key" in
# :flag.case
--force | -f)
# :flag.case_no_arg
args[--force]=1
shift
;;
# :flag.case # :flag.case
--quiet | -q) --quiet | -q)

View File

@ -40,6 +40,9 @@ commands:
help: project name or id help: project name or id
required: true required: true
flags: flags:
- long: --force
short: -f
help: delete all projects with the same name
- long: --quiet - long: --quiet
short: -q short: -q
help: suppress log output, print errors only help: suppress log output, print errors only

View File

@ -1,9 +1,13 @@
# shellcheck shell=bash disable=SC2154 # shellcheck shell=bash disable=SC2154
# get project ids # get project id(s)
projectids="$(get_ids "${args[project]}")" if [[ ${args[--force]} ]]; then
projectids="$(get_ids "${args[project]}")"
else
projectids="$(get_id "${args[project]}")"
fi
# loop over multiple project ids # loop over one or more project ids
for projectid in ${projectids}; do for projectid in ${projectids}; do
# get csrf token and post data # get csrf token and post data
if response="$(curl -fs --data "project=${projectid}" "${OPENREFINE_URL}/command/core/delete-project$(get_csrf)")"; then if response="$(curl -fs --data "project=${projectid}" "${OPENREFINE_URL}/command/core/delete-project$(get_csrf)")"; then

View File

@ -1,22 +1,22 @@
# get project id (derived from project name if needed) # get project id (derived from project name if needed)
# shellcheck shell=bash # shellcheck shell=bash
function get_id() { function get_id() {
local response projects ids local response projects projectid
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}"
fi fi
if ! projects="$(echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"' | grep -e ":$1$" -e "^$1:")"; then if ! projects="$(echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"' | grep -e ":$1$" -e "^$1:")"; then
error "project $1 not found" error "project $1 not found"
fi fi
ids=$(echo "$projects" | cut -d : -f 1) projectid=$(echo "$projects" | cut -d : -f 1)
if ! [[ "${#ids}" == 13 ]]; then if ! [[ "${#projectid}" == 13 ]]; then
error "multiple projects found" "$projects" error "multiple projects found" "$projects"
fi fi
echo "$ids" echo "$projectid"
} }
function get_ids() { function get_ids() {
local response projects ids local response projects
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}"
fi fi

View File

@ -51,7 +51,7 @@ send_completions() {
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'delete\'*)' echo $' \'delete\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --quiet -h -q")" -- "$cur" )' echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--force --help --quiet -f -h -q")" -- "$cur" )'
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'import\'*)' echo $' \'import\'*)'

View File

@ -19,6 +19,11 @@ orcli import csv "${t}.csv"
orcli list | grep "${t} csv" orcli list | grep "${t} csv"
orcli delete "${t} csv" orcli delete "${t} csv"
orcli list | grep "${t} csv" > "${t}.output" || exit 0 orcli list | grep "${t} csv" > "${t}.output" || exit 0
orcli import csv "${t}.csv"
orcli import csv "${t}.csv"
orcli list | grep "${t} csv"
orcli delete --force "${t} csv"
orcli list | grep "${t} csv" >> "${t}.output" || exit 0
# test # test
diff -u "${t}.assert" "${t}.output" diff -u "${t}.assert" "${t}.output"