Skip to content

Commit d1d5421

Browse files
Merge pull request #138 from opencultureconsulting/137-check-if-stdin-is-present-sometimes-fails
add sleepy retry to stdin-check
2 parents f7ce61c + 4259757 commit d1d5421

File tree

11 files changed

+163
-90
lines changed

11 files changed

+163
-90
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ Bash script to control OpenRefine via [its HTTP API](https://docs.openrefine.org
1212
* allows execution of arbitrary bash scripts
1313
* interactive mode for playing around and debugging
1414
* your existing OpenRefine data will not be touched
15+
* supports stdin, multiple files and URLs
1516
* import CSV, TSV, JSON, JSONL, ~~line-based TXT, fixed-width TXT or XML~~
16-
* supports stdin, multiple files and URLs
1717
* transform data by providing an [undo/redo](https://docs.openrefine.org/manual/running#history-undoredo) JSON file
1818
* orcli calls specific endpoints for each operation to provide improved error handling and logging
19-
* supports stdin, multiple files and URLs
2019
* export to CSV, TSV, JSONL, ~~HTML, XLS, XLSX, ODS~~
2120
* [templating export](https://docs.openrefine.org/manual/exporting#templating-exporter) to additional formats like JSON or XML
2221

help/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# orcli 0.4.1
1+
# orcli 0.4.2
22

33
## command help screens
44

orcli

Lines changed: 97 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
# This script was generated by bashly 1.2.6 (https://bashly.dannyb.co)
2+
# This script was generated by bashly 1.2.13 (https://bashly.dev)
33
# Modifying it manually is not recommended
44

55
# :wrapper.bash3_bouncer
@@ -1340,15 +1340,6 @@ inspect_args() {
13401340
echo args: none
13411341
fi
13421342

1343-
if ((${#other_args[@]})); then
1344-
echo
1345-
echo other_args:
1346-
echo "- \${other_args[*]} = ${other_args[*]}"
1347-
for i in "${!other_args[@]}"; do
1348-
echo "- \${other_args[$i]} = ${other_args[$i]}"
1349-
done
1350-
fi
1351-
13521343
if ((${#deps[@]})); then
13531344
readarray -t sorted_keys < <(printf '%s\n' "${!deps[@]}" | sort)
13541345
echo
@@ -1774,10 +1765,15 @@ orcli_import_csv_command() {
17741765
# call init_import function to eval args and to set basic post data
17751766
init_import
17761767

1777-
# check if stdin is present if selected
1778-
if [[ ${file} == '-' ]] && ! read -u 0 -t 0; then
1779-
orcli_import_csv_usage
1780-
exit 1
1768+
# exit if stdin is selected but not present
1769+
if [[ ${file} == '-' ]]; then
1770+
if ! read -u 0 -t 0; then
1771+
sleep 1
1772+
if ! read -u 0 -t 0; then
1773+
orcli_import_csv_usage
1774+
exit 1
1775+
fi
1776+
fi
17811777
fi
17821778

17831779
# assemble specific post data (some options require json format)
@@ -1867,10 +1863,15 @@ orcli_import_tsv_command() {
18671863
# call init_import function to eval args and to set basic post data
18681864
init_import
18691865

1870-
# check if stdin is present if selected
1871-
if [[ ${file} == '-' ]] && ! read -u 0 -t 0; then
1872-
orcli_import_tsv_usage
1873-
exit 1
1866+
# exit if stdin is selected but not present
1867+
if [[ ${file} == '-' ]]; then
1868+
if ! read -u 0 -t 0; then
1869+
sleep 1
1870+
if ! read -u 0 -t 0; then
1871+
orcli_import_tsv_usage
1872+
exit 1
1873+
fi
1874+
fi
18741875
fi
18751876

18761877
# assemble specific post data (some options require json format)
@@ -1960,10 +1961,15 @@ orcli_import_json_command() {
19601961
# call init_import function to eval args and to set basic post data
19611962
init_import
19621963

1963-
# check if stdin is present if selected
1964-
if [[ ${file} == '-' ]] && ! read -u 0 -t 0; then
1965-
orcli_import_json_usage
1966-
exit 1
1964+
# exit if stdin is selected but not present
1965+
if [[ ${file} == '-' ]]; then
1966+
if ! read -u 0 -t 0; then
1967+
sleep 1
1968+
if ! read -u 0 -t 0; then
1969+
orcli_import_json_usage
1970+
exit 1
1971+
fi
1972+
fi
19671973
fi
19681974

19691975
# assemble specific post data (some options require json format)
@@ -2020,10 +2026,15 @@ orcli_import_jsonl_command() {
20202026
# call init_import function to eval args and to set basic post data
20212027
init_import
20222028

2023-
# check if stdin is present if selected
2024-
if [[ ${file} == '-' ]] && ! read -u 0 -t 0; then
2025-
orcli_import_jsonl_usage
2026-
exit 1
2029+
# exit if stdin is selected but not present
2030+
if [[ ${file} == '-' ]]; then
2031+
if ! read -u 0 -t 0; then
2032+
sleep 1
2033+
if ! read -u 0 -t 0; then
2034+
orcli_import_jsonl_usage
2035+
exit 1
2036+
fi
2037+
fi
20272038
fi
20282039

20292040
# assemble specific post data (some options require json format)
@@ -2263,11 +2274,14 @@ orcli_transform_command() {
22632274
# src/transform_command.sh
22642275
# shellcheck shell=bash disable=SC2154 disable=SC2155
22652276

2266-
# check if stdin is present if selected
2277+
# exit if stdin is selected but not present
22672278
if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]]; then
22682279
if ! read -u 0 -t 0; then
2269-
orcli_transform_usage
2270-
exit 1
2280+
sleep 1
2281+
if ! read -u 0 -t 0; then
2282+
orcli_transform_usage
2283+
exit 1
2284+
fi
22712285
fi
22722286
fi
22732287

@@ -2297,7 +2311,7 @@ orcli_transform_command() {
22972311
if [[ "${files[$i]}" == '-' ]] || [[ "${files[$i]}" == '"-"' ]]; then
22982312
# exit if stdin is selected but not present
22992313
if ! read -u 0 -t 0; then
2300-
orcli_transform_usage
2314+
orcli_run_usage
23012315
exit 1
23022316
fi
23032317
else
@@ -2553,8 +2567,11 @@ orcli_export_template_command() {
25532567
if [[ "${args[file]}" == '-' ]] || [[ "${args[file]}" == '"-"' ]]; then
25542568
# exit if stdin is selected but not present
25552569
if ! read -u 0 -t 0; then
2556-
orcli_export_template_usage
2557-
exit 1
2570+
sleep 1
2571+
if ! read -u 0 -t 0; then
2572+
orcli_export_template_usage
2573+
exit 1
2574+
fi
25582575
fi
25592576
else
25602577
# exit if file does not exist
@@ -2601,8 +2618,11 @@ orcli_run_command() {
26012618
# exit if stdin is selected but not present
26022619
if ! [[ ${args[--interactive]} ]]; then
26032620
if ! read -u 0 -t 0; then
2604-
orcli_run_usage
2605-
exit 1
2621+
sleep 1
2622+
if ! read -u 0 -t 0; then
2623+
orcli_run_usage
2624+
exit 1
2625+
fi
26062626
fi
26072627
fi
26082628
else
@@ -2661,13 +2681,16 @@ orcli_run_command() {
26612681
export OPENREFINE_TMPDIR OPENREFINE_URL OPENREFINE_PID
26622682
if [[ ${args[file]} == '-' || ${args[file]} == '"-"' ]]; then
26632683
if ! read -u 0 -t 0; then
2664-
# case 1: interactive mode if stdin is selected but not present
2665-
bash --rcfile <(
2666-
cat ~/.bashrc
2667-
echo "alias orcli=${scriptpath}/orcli"
2668-
interactive
2669-
) -i </dev/tty
2670-
exit
2684+
sleep 1
2685+
if ! read -u 0 -t 0; then
2686+
# case 1: interactive mode if stdin is selected but not present
2687+
bash --rcfile <(
2688+
cat ~/.bashrc
2689+
echo "alias orcli=${scriptpath}/orcli"
2690+
interactive
2691+
) -i </dev/tty
2692+
exit
2693+
fi
26712694
fi
26722695
fi
26732696
if [[ ${args[--interactive]} ]]; then
@@ -2728,19 +2751,26 @@ parse_requirements() {
27282751
env_var_names+=("OPENREFINE_URL")
27292752

27302753
# :command.dependencies_filter
2731-
if command -v curl >/dev/null 2>&1; then
2732-
deps['curl']="$(command -v curl | head -n1)"
2733-
else
2754+
missing_deps=
2755+
# :dependency.filter
2756+
if ! command -v curl >/dev/null 2>&1; then
27342757
printf "missing dependency: curl\n" >&2
2735-
printf "%s\n" "https://curl.se" >&2
2736-
exit 1
2758+
printf "%s\n\n" "https://curl.se" >&2
2759+
missing_deps=1
2760+
else
2761+
deps['curl']="$(command -v curl | head -n1)"
27372762
fi
27382763

2739-
if command -v jq >/dev/null 2>&1; then
2740-
deps['jq']="$(command -v jq | head -n1)"
2741-
else
2764+
# :dependency.filter
2765+
if ! command -v jq >/dev/null 2>&1; then
27422766
printf "missing dependency: jq\n" >&2
2743-
printf "%s\n" "https://github.com/stedolan/jq" >&2
2767+
printf "%s\n\n" "https://github.com/stedolan/jq" >&2
2768+
missing_deps=1
2769+
else
2770+
deps['jq']="$(command -v jq | head -n1)"
2771+
fi
2772+
2773+
if [[ -n $missing_deps ]]; then
27442774
exit 1
27452775
fi
27462776

@@ -2971,6 +3001,7 @@ orcli_delete_parse_requirements() {
29713001

29723002
esac
29733003
done
3004+
29743005
# :command.required_args_filter
29753006
if [[ -z ${args['project']+x} ]]; then
29763007
printf "missing required argument: PROJECT\nusage: orcli delete PROJECT [OPTIONS]\n" >&2
@@ -4016,6 +4047,7 @@ orcli_info_parse_requirements() {
40164047

40174048
esac
40184049
done
4050+
40194051
# :command.required_args_filter
40204052
if [[ -z ${args['project']+x} ]]; then
40214053
printf "missing required argument: PROJECT\nusage: orcli info PROJECT\n" >&2
@@ -4090,6 +4122,7 @@ orcli_search_parse_requirements() {
40904122

40914123
esac
40924124
done
4125+
40934126
# :command.required_args_filter
40944127
if [[ -z ${args['project']+x} ]]; then
40954128
printf "missing required argument: PROJECT\nusage: orcli search PROJECT [REGEX] [OPTIONS]\n" >&2
@@ -4233,6 +4266,7 @@ orcli_sort_columns_parse_requirements() {
42334266

42344267
esac
42354268
done
4269+
42364270
# :command.required_args_filter
42374271
if [[ -z ${args['project']+x} ]]; then
42384272
printf "missing required argument: PROJECT\nusage: orcli sort columns PROJECT [OPTIONS]\n" >&2
@@ -4347,6 +4381,7 @@ orcli_transform_parse_requirements() {
43474381

43484382
esac
43494383
done
4384+
43504385
# :command.required_args_filter
43514386
if [[ -z ${args['project']+x} ]]; then
43524387
printf "missing required argument: PROJECT\nusage: orcli transform PROJECT [FILE...] [OPTIONS]\n" >&2
@@ -4573,6 +4608,7 @@ orcli_export_jsonl_parse_requirements() {
45734608

45744609
esac
45754610
done
4611+
45764612
# :command.required_args_filter
45774613
if [[ -z ${args['project']+x} ]]; then
45784614
printf "missing required argument: PROJECT\nusage: orcli export jsonl PROJECT [OPTIONS]\n" >&2
@@ -4732,6 +4768,7 @@ orcli_export_csv_parse_requirements() {
47324768

47334769
esac
47344770
done
4771+
47354772
# :command.required_args_filter
47364773
if [[ -z ${args['project']+x} ]]; then
47374774
printf "missing required argument: PROJECT\nusage: orcli export csv PROJECT [OPTIONS]\n" >&2
@@ -4878,6 +4915,7 @@ orcli_export_tsv_parse_requirements() {
48784915

48794916
esac
48804917
done
4918+
48814919
# :command.required_args_filter
48824920
if [[ -z ${args['project']+x} ]]; then
48834921
printf "missing required argument: PROJECT\nusage: orcli export tsv PROJECT [OPTIONS]\n" >&2
@@ -5055,6 +5093,7 @@ orcli_export_template_parse_requirements() {
50555093

50565094
esac
50575095
done
5096+
50585097
# :command.required_args_filter
50595098
if [[ -z ${args['project']+x} ]]; then
50605099
printf "missing required argument: PROJECT\nusage: orcli export template PROJECT [FILE] [OPTIONS]\n" >&2
@@ -5178,8 +5217,7 @@ orcli_run_parse_requirements() {
51785217

51795218
# :command.initialize
51805219
initialize() {
5181-
version="0.4.1"
5182-
long_usage=''
5220+
declare -g version="0.4.2"
51835221
set -e
51845222

51855223
# :command.environment_variables_default
@@ -5191,11 +5229,13 @@ initialize() {
51915229

51925230
# :command.run
51935231
run() {
5232+
# :command.globals
5233+
declare -g long_usage=''
51945234
declare -g -A args=()
51955235
declare -g -A deps=()
5196-
declare -g -a other_args=()
51975236
declare -g -a env_var_names=()
51985237
declare -g -a input=()
5238+
51995239
normalize_input "$@"
52005240
parse_requirements "${input[@]}"
52015241

@@ -5223,5 +5263,7 @@ run() {
52235263
esac
52245264
}
52255265

5226-
initialize
5227-
run "$@"
5266+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
5267+
initialize
5268+
run "$@"
5269+
fi

src/bashly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: orcli
22
help: OpenRefine command-line interface written in Bash
3-
version: 0.4.1
3+
version: 0.4.2
44
footer: https://github.com/opencultureconsulting/orcli
55

66
dependencies:

src/export_template_command.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ fi
1919
if [[ "${args[file]}" == '-' ]] || [[ "${args[file]}" == '"-"' ]]; then
2020
# exit if stdin is selected but not present
2121
if ! read -u 0 -t 0; then
22-
orcli_export_template_usage
23-
exit 1
22+
sleep 1
23+
if ! read -u 0 -t 0; then
24+
orcli_export_template_usage
25+
exit 1
26+
fi
2427
fi
2528
else
2629
# exit if file does not exist

src/import_csv_command.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
# call init_import function to eval args and to set basic post data
44
init_import
55

6-
# check if stdin is present if selected
7-
if [[ ${file} == '-' ]] && ! read -u 0 -t 0; then
8-
orcli_import_csv_usage
9-
exit 1
6+
# exit if stdin is selected but not present
7+
if [[ ${file} == '-' ]]; then
8+
if ! read -u 0 -t 0; then
9+
sleep 1
10+
if ! read -u 0 -t 0; then
11+
orcli_import_csv_usage
12+
exit 1
13+
fi
14+
fi
1015
fi
1116

1217
# assemble specific post data (some options require json format)

0 commit comments

Comments
 (0)