From 5b2df6fea0f3a4de5ca6931a0444d312e81eee4d Mon Sep 17 00:00:00 2001 From: felixlohmeier Date: Fri, 25 Mar 2022 22:02:28 +0000 Subject: [PATCH] shfmt and shebang --- .gitpod.yml | 8 ++--- orcli | 71 +++++++++++++++++++++++---------------------- src/bashly.yml | 45 ++++++++++++++-------------- src/info_command.sh | 5 +--- src/initialize.sh | 7 ++--- src/lib/error.sh | 3 +- src/lib/get_csrf.sh | 19 ++++++------ src/lib/get_id.sh | 39 +++++++++++++------------ src/list_command.sh | 4 +-- 9 files changed, 99 insertions(+), 102 deletions(-) diff --git a/.gitpod.yml b/.gitpod.yml index 8b9e0c6..1d06172 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -2,10 +2,10 @@ tasks: - name: install bashly and OpenRefine init: | - 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 - tar --exclude 'licenses' --exclude 'LICENSE.txt' --exclude 'README.md' -xzf openrefine.tar.gz --strip 1 - rm openrefine.tar.gz + 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 + tar --exclude 'licenses' --exclude 'LICENSE.txt' --exclude 'README.md' -xzf openrefine.tar.gz --strip 1 + rm openrefine.tar.gz ports: - port: 3333 diff --git a/orcli b/orcli index 24015ff..f5133f3 100755 --- a/orcli +++ b/orcli @@ -186,65 +186,65 @@ 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 - local response - response=$(curl -fs "${OPENREFINE_URL}/command/core/get-csrf-token") - if ! [[ "${response}" == '{"token":"'* ]]; then - error "getting CSRF token failed!" - exit 1 +function get_csrf() { + if [[ "${OPENREFINE_CSRF}" == true ]]; then + local response + response=$(curl -fs "${OPENREFINE_URL}/command/core/get-csrf-token") + if ! [[ "${response}" == '{"token":"'* ]]; then + error "getting CSRF token failed!" + exit 1 + fi + echo "?csrf_token=$(echo "$response" | cut -d \" -f 4)" fi - echo "?csrf_token=$(echo "$response" | cut -d \" -f 4)" -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 - 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 - error "project ${args[project]} not found" - exit 1 -fi -ids=$(echo "$projects" | cut -d : -f 1) -if ! [[ "${#ids}" == 13 ]]; then - error "multiple projects found" - echo >&2 "$projects" - exit 1 -fi -echo "$ids" +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 + error "project ${args[project]} not found" + exit 1 + fi + ids=$(echo "$projects" | cut -d : -f 1) + if ! [[ "${#ids}" == 13 ]]; then + error "multiple projects found" + echo >&2 "$projects" + exit 1 + 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 diff --git a/src/bashly.yml b/src/bashly.yml index a3d0a0b..d443558 100644 --- a/src/bashly.yml +++ b/src/bashly.yml @@ -3,33 +3,32 @@ help: OpenRefine command-line interface written in Bash version: 0.1.0 dependencies: -- curl -- jq + - curl + - jq environment_variables: -- name: OPENREFINE_URL - help: URL to OpenRefine server - default: "http://localhost:3333" -- name: OPENREFINE_CSRF - default: "true" - help: set to false for OpenRefine < 3.3 + - name: OPENREFINE_URL + help: URL to OpenRefine server + default: "http://localhost:3333" + - 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 + help: show project metadata + args: + - name: project + help: project name or id + required: true + examples: + - info clipboard + - info 1234567890123 -- name: info - help: show project metadata - args: - - name: project - help: project name or id - required: true - examples: - - info clipboard - - info 1234567890123 - -- name: list - help: list projects on OpenRefine server + - name: list + help: list projects on OpenRefine server diff --git a/src/info_command.sh b/src/info_command.sh index 2efddfb..68bb0f6 100644 --- a/src/info_command.sh +++ b/src/info_command.sh @@ -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 diff --git a/src/initialize.sh b/src/initialize.sh index 3cfee95..a3b9c35 100644 --- a/src/initialize.sh +++ b/src/initialize.sh @@ -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 diff --git a/src/lib/error.sh b/src/lib/error.sh index 41774da..a6f0bd4 100644 --- a/src/lib/error.sh +++ b/src/lib/error.sh @@ -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 $*" } diff --git a/src/lib/get_csrf.sh b/src/lib/get_csrf.sh index e10ae5a..62ba32a 100644 --- a/src/lib/get_csrf.sh +++ b/src/lib/get_csrf.sh @@ -1,12 +1,13 @@ +#!/usr/bin/env bash # get CSRF token (introduced in OpenRefine 3.3) -function get_csrf { -if [[ "${OPENREFINE_CSRF}" == true ]]; then - local response - response=$(curl -fs "${OPENREFINE_URL}/command/core/get-csrf-token") - if ! [[ "${response}" == '{"token":"'* ]]; then - error "getting CSRF token failed!" - exit 1 +function get_csrf() { + if [[ "${OPENREFINE_CSRF}" == true ]]; then + local response + response=$(curl -fs "${OPENREFINE_URL}/command/core/get-csrf-token") + if ! [[ "${response}" == '{"token":"'* ]]; then + error "getting CSRF token failed!" + exit 1 + fi + echo "?csrf_token=$(echo "$response" | cut -d \" -f 4)" fi - echo "?csrf_token=$(echo "$response" | cut -d \" -f 4)" -fi } diff --git a/src/lib/get_id.sh b/src/lib/get_id.sh index 3a0150a..edbc930 100644 --- a/src/lib/get_id.sh +++ b/src/lib/get_id.sh @@ -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 - 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 - error "project ${args[project]} not found" - exit 1 -fi -ids=$(echo "$projects" | cut -d : -f 1) -if ! [[ "${#ids}" == 13 ]]; then - error "multiple projects found" - echo >&2 "$projects" - exit 1 -fi -echo "$ids" +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 + error "project ${args[project]} not found" + exit 1 + fi + ids=$(echo "$projects" | cut -d : -f 1) + if ! [[ "${#ids}" == 13 ]]; then + error "multiple projects found" + echo >&2 "$projects" + exit 1 + fi + echo "$ids" } diff --git a/src/list_command.sh b/src/list_command.sh index 93cad38..39d4c58 100644 --- a/src/list_command.sh +++ b/src/list_command.sh @@ -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)"'