shfmt and shebang
This commit is contained in:
parent
5d1cd632bd
commit
5b2df6fea0
|
@ -2,10 +2,10 @@
|
||||||
tasks:
|
tasks:
|
||||||
- name: install bashly and OpenRefine
|
- name: install bashly and OpenRefine
|
||||||
init: |
|
init: |
|
||||||
gem install --silent bashly
|
gem install --silent bashly
|
||||||
wget -q -O openrefine.tar.gz https://github.com/OpenRefine/OpenRefine/releases/download/3.5.2/openrefine-linux-3.5.2.tar.gz
|
wget -q -O openrefine.tar.gz https://github.com/OpenRefine/OpenRefine/releases/download/3.5.2/openrefine-linux-3.5.2.tar.gz
|
||||||
tar --exclude 'licenses' --exclude 'LICENSE.txt' --exclude 'README.md' -xzf openrefine.tar.gz --strip 1
|
tar --exclude 'licenses' --exclude 'LICENSE.txt' --exclude 'README.md' -xzf openrefine.tar.gz --strip 1
|
||||||
rm openrefine.tar.gz
|
rm openrefine.tar.gz
|
||||||
|
|
||||||
ports:
|
ports:
|
||||||
- port: 3333
|
- port: 3333
|
||||||
|
|
71
orcli
71
orcli
|
@ -186,65 +186,65 @@ inspect_args() {
|
||||||
|
|
||||||
# :command.user_lib
|
# :command.user_lib
|
||||||
# :src/lib/error.sh
|
# :src/lib/error.sh
|
||||||
|
#!/usr/bin/env bash
|
||||||
# log error message to STDERR
|
# log error message to STDERR
|
||||||
function error {
|
function error() {
|
||||||
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')]: ERROR $*"
|
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')]: ERROR $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
# :src/lib/get_csrf.sh
|
# :src/lib/get_csrf.sh
|
||||||
|
#!/usr/bin/env bash
|
||||||
# get CSRF token (introduced in OpenRefine 3.3)
|
# get CSRF token (introduced in OpenRefine 3.3)
|
||||||
function get_csrf {
|
function get_csrf() {
|
||||||
if [[ "${OPENREFINE_CSRF}" == true ]]; then
|
if [[ "${OPENREFINE_CSRF}" == true ]]; then
|
||||||
local response
|
local response
|
||||||
response=$(curl -fs "${OPENREFINE_URL}/command/core/get-csrf-token")
|
response=$(curl -fs "${OPENREFINE_URL}/command/core/get-csrf-token")
|
||||||
if ! [[ "${response}" == '{"token":"'* ]]; then
|
if ! [[ "${response}" == '{"token":"'* ]]; then
|
||||||
error "getting CSRF token failed!"
|
error "getting CSRF token failed!"
|
||||||
exit 1
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "?csrf_token=$(echo "$response" | cut -d \" -f 4)"
|
||||||
fi
|
fi
|
||||||
echo "?csrf_token=$(echo "$response" | cut -d \" -f 4)"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# :src/lib/get_id.sh
|
# :src/lib/get_id.sh
|
||||||
|
#!/usr/bin/env bash
|
||||||
# get project id (derived from project name if needed)
|
# get project id (derived from project name if needed)
|
||||||
function get_id {
|
function get_id() {
|
||||||
local response
|
local response
|
||||||
local projects
|
local projects
|
||||||
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
|
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
|
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"
|
||||||
echo >&2 "$projects"
|
echo >&2 "$projects"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "$ids"
|
echo "$ids"
|
||||||
}
|
}
|
||||||
|
|
||||||
# :command.command_functions
|
# :command.command_functions
|
||||||
# :command.function
|
# :command.function
|
||||||
orcli_info_command() {
|
orcli_info_command() {
|
||||||
# :src/info_command.sh
|
# :src/info_command.sh
|
||||||
echo "# this file is located in 'src/info_command.sh'"
|
#!/usr/bin/env bash
|
||||||
echo "# code for 'openrefine-cli.sh info' goes here"
|
|
||||||
echo "# you can edit it freely and regenerate (it will not be overwritten)"
|
|
||||||
inspect_args
|
|
||||||
get_id
|
get_id
|
||||||
}
|
}
|
||||||
|
|
||||||
# :command.function
|
# :command.function
|
||||||
orcli_list_command() {
|
orcli_list_command() {
|
||||||
# :src/list_command.sh
|
# :src/list_command.sh
|
||||||
|
#!/usr/bin/env bash
|
||||||
# get all project metadata and reshape json to print a list
|
# get all project metadata and reshape json to print a list
|
||||||
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"
|
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"; then
|
||||||
then
|
|
||||||
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
||||||
else
|
else
|
||||||
echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"'
|
echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"'
|
||||||
|
@ -432,6 +432,7 @@ initialize() {
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# :src/initialize.sh
|
# :src/initialize.sh
|
||||||
|
#!/usr/bin/env bash
|
||||||
}
|
}
|
||||||
|
|
||||||
# :command.run
|
# :command.run
|
||||||
|
|
|
@ -3,33 +3,32 @@ help: OpenRefine command-line interface written in Bash
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
- curl
|
- curl
|
||||||
- jq
|
- jq
|
||||||
|
|
||||||
environment_variables:
|
environment_variables:
|
||||||
- name: OPENREFINE_URL
|
- name: OPENREFINE_URL
|
||||||
help: URL to OpenRefine server
|
help: URL to OpenRefine server
|
||||||
default: "http://localhost:3333"
|
default: "http://localhost:3333"
|
||||||
- name: OPENREFINE_CSRF
|
- name: OPENREFINE_CSRF
|
||||||
default: "true"
|
default: "true"
|
||||||
help: set to false for OpenRefine < 3.3
|
help: set to false for OpenRefine < 3.3
|
||||||
|
|
||||||
examples:
|
examples:
|
||||||
- orcli list
|
- orcli list
|
||||||
- orcli info clipboard
|
- orcli info clipboard
|
||||||
- orcli info 1234567890123
|
- orcli info 1234567890123
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
|
- name: info
|
||||||
|
help: show project metadata
|
||||||
|
args:
|
||||||
|
- name: project
|
||||||
|
help: project name or id
|
||||||
|
required: true
|
||||||
|
examples:
|
||||||
|
- info clipboard
|
||||||
|
- info 1234567890123
|
||||||
|
|
||||||
- name: info
|
- name: list
|
||||||
help: show project metadata
|
help: list projects on OpenRefine server
|
||||||
args:
|
|
||||||
- name: project
|
|
||||||
help: project name or id
|
|
||||||
required: true
|
|
||||||
examples:
|
|
||||||
- info clipboard
|
|
||||||
- info 1234567890123
|
|
||||||
|
|
||||||
- name: list
|
|
||||||
help: list projects on OpenRefine server
|
|
||||||
|
|
|
@ -1,5 +1,2 @@
|
||||||
echo "# this file is located in 'src/info_command.sh'"
|
#!/usr/bin/env bash
|
||||||
echo "# code for 'openrefine-cli.sh info' goes here"
|
|
||||||
echo "# you can edit it freely and regenerate (it will not be overwritten)"
|
|
||||||
inspect_args
|
|
||||||
get_id
|
get_id
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
## Code here runs inside the initialize() function
|
## Code here runs inside the initialize() function
|
||||||
## Use it for anything that you need to run before any other function, like
|
## Use it for anything that you need to run before any other function
|
||||||
## setting environment vairables:
|
|
||||||
## CONFIG_FILE=settings.ini
|
|
||||||
##
|
|
||||||
## Feel free to empty (but not delete) this file.
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
# log error message to STDERR
|
# log error message to STDERR
|
||||||
function error {
|
function error() {
|
||||||
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')]: ERROR $*"
|
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')]: ERROR $*"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
# get CSRF token (introduced in OpenRefine 3.3)
|
# get CSRF token (introduced in OpenRefine 3.3)
|
||||||
function get_csrf {
|
function get_csrf() {
|
||||||
if [[ "${OPENREFINE_CSRF}" == true ]]; then
|
if [[ "${OPENREFINE_CSRF}" == true ]]; then
|
||||||
local response
|
local response
|
||||||
response=$(curl -fs "${OPENREFINE_URL}/command/core/get-csrf-token")
|
response=$(curl -fs "${OPENREFINE_URL}/command/core/get-csrf-token")
|
||||||
if ! [[ "${response}" == '{"token":"'* ]]; then
|
if ! [[ "${response}" == '{"token":"'* ]]; then
|
||||||
error "getting CSRF token failed!"
|
error "getting CSRF token failed!"
|
||||||
exit 1
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "?csrf_token=$(echo "$response" | cut -d \" -f 4)"
|
||||||
fi
|
fi
|
||||||
echo "?csrf_token=$(echo "$response" | cut -d \" -f 4)"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
# get project id (derived from project name if needed)
|
# get project id (derived from project name if needed)
|
||||||
function get_id {
|
function get_id() {
|
||||||
local response
|
local response
|
||||||
local projects
|
local projects
|
||||||
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
|
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
|
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"
|
||||||
echo >&2 "$projects"
|
echo >&2 "$projects"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "$ids"
|
echo "$ids"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
# get all project metadata and reshape json to print a list
|
# get all project metadata and reshape json to print a list
|
||||||
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"
|
if ! response="$(curl -fs --get "${OPENREFINE_URL}/command/core/get-all-project-metadata")"; then
|
||||||
then
|
|
||||||
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
error "no OpenRefine reachable/running at ${OPENREFINE_URL}"
|
||||||
else
|
else
|
||||||
echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"'
|
echo "$response" | jq -r '.projects | keys[] as $k | "\($k):\(.[$k] | .name)"'
|
||||||
|
|
Loading…
Reference in New Issue