Merge pull request #11 from opencultureconsulting:felixlohmeier/shfmt-and-shellcheck-10

shfmt and shebang
This commit is contained in:
Felix Lohmeier 2022-03-25 23:04:26 +01:00 committed by GitHub
commit 7de612553d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 99 additions and 102 deletions

45
orcli
View File

@ -186,15 +186,17 @@ inspect_args() {
# :command.user_lib
# :src/lib/error.sh
#!/usr/bin/env bash
# log error message to STDERR
function error {
function error() {
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')]: ERROR $*"
}
# :src/lib/get_csrf.sh
#!/usr/bin/env bash
# get CSRF token (introduced in OpenRefine 3.3)
function get_csrf {
if [[ "${OPENREFINE_CSRF}" == true ]]; then
function get_csrf() {
if [[ "${OPENREFINE_CSRF}" == true ]]; then
local response
response=$(curl -fs "${OPENREFINE_URL}/command/core/get-csrf-token")
if ! [[ "${response}" == '{"token":"'* ]]; then
@ -202,49 +204,47 @@ if [[ "${OPENREFINE_CSRF}" == true ]]; then
exit 1
fi
echo "?csrf_token=$(echo "$response" | cut -d \" -f 4)"
fi
fi
}
# :src/lib/get_id.sh
#!/usr/bin/env bash
# get project id (derived from project name if needed)
function get_id {
local response
local projects
local ids
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"; then
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}"
exit 1
fi
if ! projects="$(echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"' | grep "${args[project]}")"; then
fi
if ! projects="$(echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"' | grep "${args[project]}")"; then
error "project ${args[project]} not found"
exit 1
fi
ids=$(echo "$projects" | cut -d : -f 1)
if ! [[ "${#ids}" == 13 ]]; then
fi
ids=$(echo "$projects" | cut -d : -f 1)
if ! [[ "${#ids}" == 13 ]]; then
error "multiple projects found"
echo >&2 "$projects"
exit 1
fi
echo "$ids"
fi
echo "$ids"
}
# :command.command_functions
# :command.function
orcli_info_command() {
# :src/info_command.sh
echo "# this file is located in 'src/info_command.sh'"
echo "# code for 'openrefine-cli.sh info' goes here"
echo "# you can edit it freely and regenerate (it will not be overwritten)"
inspect_args
#!/usr/bin/env bash
get_id
}
# :command.function
orcli_list_command() {
# :src/list_command.sh
#!/usr/bin/env bash
# get all project metadata and reshape json to print a list
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}"
else
echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"'
@ -432,6 +432,7 @@ initialize() {
set -e
# :src/initialize.sh
#!/usr/bin/env bash
}
# :command.run

View File

@ -3,25 +3,24 @@ help: OpenRefine command-line interface written in Bash
version: 0.1.0
dependencies:
- curl
- jq
- curl
- jq
environment_variables:
- name: OPENREFINE_URL
- name: OPENREFINE_URL
help: URL to OpenRefine server
default: "http://localhost:3333"
- name: OPENREFINE_CSRF
- name: OPENREFINE_CSRF
default: "true"
help: set to false for OpenRefine < 3.3
examples:
- orcli list
- orcli info clipboard
- orcli info 1234567890123
- orcli list
- orcli info clipboard
- orcli info 1234567890123
commands:
- name: info
- name: info
help: show project metadata
args:
- name: project
@ -31,5 +30,5 @@ commands:
- info clipboard
- info 1234567890123
- name: list
- name: list
help: list projects on OpenRefine server

View File

@ -1,5 +1,2 @@
echo "# this file is located in 'src/info_command.sh'"
echo "# code for 'openrefine-cli.sh info' goes here"
echo "# you can edit it freely and regenerate (it will not be overwritten)"
inspect_args
#!/usr/bin/env bash
get_id

View File

@ -1,6 +1,3 @@
#!/usr/bin/env bash
## Code here runs inside the initialize() function
## Use it for anything that you need to run before any other function, like
## setting environment vairables:
## CONFIG_FILE=settings.ini
##
## Feel free to empty (but not delete) this file.
## Use it for anything that you need to run before any other function

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash
# log error message to STDERR
function error {
function error() {
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')]: ERROR $*"
}

View File

@ -1,6 +1,7 @@
#!/usr/bin/env bash
# get CSRF token (introduced in OpenRefine 3.3)
function get_csrf {
if [[ "${OPENREFINE_CSRF}" == true ]]; then
function get_csrf() {
if [[ "${OPENREFINE_CSRF}" == true ]]; then
local response
response=$(curl -fs "${OPENREFINE_URL}/command/core/get-csrf-token")
if ! [[ "${response}" == '{"token":"'* ]]; then
@ -8,5 +9,5 @@ if [[ "${OPENREFINE_CSRF}" == true ]]; then
exit 1
fi
echo "?csrf_token=$(echo "$response" | cut -d \" -f 4)"
fi
fi
}

View File

@ -1,21 +1,22 @@
#!/usr/bin/env bash
# get project id (derived from project name if needed)
function get_id {
local response
local projects
local ids
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"; then
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}"
exit 1
fi
if ! projects="$(echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"' | grep "${args[project]}")"; then
fi
if ! projects="$(echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"' | grep "${args[project]}")"; then
error "project ${args[project]} not found"
exit 1
fi
ids=$(echo "$projects" | cut -d : -f 1)
if ! [[ "${#ids}" == 13 ]]; then
fi
ids=$(echo "$projects" | cut -d : -f 1)
if ! [[ "${#ids}" == 13 ]]; then
error "multiple projects found"
echo >&2 "$projects"
exit 1
fi
echo "$ids"
fi
echo "$ids"
}

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
# get all project metadata and reshape json to print a list
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}"
else
echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"'