From c5f17d24652e015086bdf81ad2e07114ac584589 Mon Sep 17 00:00:00 2001 From: Felix Lohmeier Date: Sun, 8 Dec 2024 22:37:39 +0000 Subject: [PATCH] add CSRF token to additional commands --- .devcontainer/devcontainer.json | 2 +- README.md | 2 +- orcli | 765 +++++++++++++------------------- src/export_jsonl_command.sh | 2 +- src/lib/post_export.sh | 2 +- src/lib/send_completions.sh | 110 ++--- 6 files changed, 369 insertions(+), 514 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 02f73c4..75f4de5 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ "image": "mcr.microsoft.com/devcontainers/universal:2", "features": { }, - "postCreateCommand": "gem install --silent bashly && wget -q -O openrefine.tar.gz https://github.com/OpenRefine/OpenRefine/releases/download/3.7.6/openrefine-linux-3.7.6.tar.gz && tar --exclude 'licenses' --exclude 'LICENSE.txt' --exclude 'licenses.xml' --exclude 'README.md' -xzf openrefine.tar.gz --strip 1 && rm openrefine.tar.gz && ln -s \"${PWD}/orcli\" ~/.local/bin/", + "postCreateCommand": "gem install --silent bashly && wget -q -O openrefine.tar.gz https://github.com/OpenRefine/OpenRefine/releases/download/3.8.7/openrefine-linux-3.8.7.tar.gz && tar --exclude 'licenses' --exclude 'LICENSE.txt' --exclude 'licenses.xml' --exclude 'README.md' -xzf openrefine.tar.gz --strip 1 && rm openrefine.tar.gz && ln -s \"${PWD}/orcli\" ~/.local/bin/", "forwardPorts": [3333], "portsAttributes": { "3333": { diff --git a/README.md b/README.md index 4e7251e..4a969b7 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Bash script to control OpenRefine via [its HTTP API](https://docs.openrefine.org ## Features -* works with latest OpenRefine version (currently 3.7) +* works with latest OpenRefine version (currently 3.8) * run batch processes (import, transform, export) * orcli takes care of starting and stopping OpenRefine with temporary workspaces * allows execution of arbitrary bash scripts diff --git a/orcli b/orcli index 621e85a..527bbed 100755 --- a/orcli +++ b/orcli @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# This script was generated by bashly 1.1.3 (https://bashly.dannyb.co) +# This script was generated by bashly 1.2.6 (https://bashly.dannyb.co) # Modifying it manually is not recommended # :wrapper.bash3_bouncer @@ -17,15 +17,7 @@ version_command() { # :command.usage orcli_usage() { - if [[ -n $long_usage ]]; then - printf "orcli - OpenRefine command-line interface written in Bash\n" - echo - - else - printf "orcli - OpenRefine command-line interface written in Bash\n" - echo - - fi + printf "orcli - OpenRefine command-line interface written in Bash\n\n" printf "%s\n" "Usage:" printf " orcli COMMAND\n" @@ -48,7 +40,7 @@ orcli_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_fixed_flags @@ -65,7 +57,7 @@ orcli_usage() { # :environment_variable.usage printf " %s\n" "OPENREFINE_URL" printf " URL to OpenRefine server\n" - printf " Default: http://localhost:3333\n" + printf " %s\n" "Default: http://localhost:3333" echo # :command.usage_examples @@ -80,29 +72,23 @@ orcli_usage() { printf " orcli export tsv \"duplicates\" --output \"duplicates.tsv\"\n" printf " orcli delete \"duplicates\"\n" printf " orcli run --interactive\n" - printf " orcli run << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\"\n orcli transform \"duplicates\" \"https://git.io/fj5ju\"\n orcli export tsv \"duplicates\"\n EOF\n" - echo + printf " orcli run << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\"\n orcli transform \"duplicates\" \"https://git.io/fj5ju\"\n orcli export tsv \"duplicates\"\nEOF\n" +echo - # :command.footer - printf "https://github.com/opencultureconsulting/orcli\n" - echo + # :command.footer + printf "https://github.com/opencultureconsulting/orcli\n" + echo - fi +fi } # :command.usage orcli_completions_usage() { if [[ -n $long_usage ]]; then - printf "orcli completions\n" - echo - - printf " Generate bash completions\n Usage: source <(orcli completions)\n" - echo - + printf "orcli completions\n\n" + printf " Generate bash completions\n Usage: source <(orcli completions)\n\n" else - printf "orcli completions - Generate bash completions\n" - echo - + printf "orcli completions - Generate bash completions\n\n" fi printf "%s\n" "Usage:" @@ -111,7 +97,7 @@ orcli_completions_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_fixed_flags @@ -124,15 +110,7 @@ orcli_completions_usage() { # :command.usage orcli_delete_usage() { - if [[ -n $long_usage ]]; then - printf "orcli delete - delete OpenRefine project\n" - echo - - else - printf "orcli delete - delete OpenRefine project\n" - echo - - fi + printf "orcli delete - delete OpenRefine project\n\n" printf "%s\n" "Usage:" printf " orcli delete PROJECT [OPTIONS]\n" @@ -140,7 +118,7 @@ orcli_delete_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_flags @@ -180,15 +158,7 @@ orcli_delete_usage() { # :command.usage orcli_import_usage() { - if [[ -n $long_usage ]]; then - printf "orcli import - commands to create OpenRefine projects from files or URLs\n" - echo - - else - printf "orcli import - commands to create OpenRefine projects from files or URLs\n" - echo - - fi + printf "orcli import - commands to create OpenRefine projects from files or URLs\n\n" printf "%s\n" "Usage:" printf " orcli import COMMAND\n" @@ -203,7 +173,7 @@ orcli_import_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_fixed_flags @@ -216,15 +186,7 @@ orcli_import_usage() { # :command.usage orcli_import_csv_usage() { - if [[ -n $long_usage ]]; then - printf "orcli import csv - import character-separated values (CSV)\n" - echo - - else - printf "orcli import csv - import character-separated values (CSV)\n" - echo - - fi + printf "orcli import csv - import character-separated values (CSV)\n\n" printf "%s\n" "Usage:" printf " orcli import csv [FILE...] [OPTIONS]\n" @@ -232,14 +194,14 @@ orcli_import_csv_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_flags # :flag.usage printf " %s\n" "--separator SEPARATOR" printf " character(s) that separates columns\n" - printf " Default: ,\n" + printf " %s\n" "Default: ," echo # :flag.usage @@ -250,6 +212,7 @@ orcli_import_csv_usage() { # :flag.usage printf " %s\n" "--columnNames COLUMNNAMES" printf " set column names (comma separated)\n hint: add --ignoreLines 1 to overwrite existing header row\n" + printf " %s\n" "Conflicts: --headerLines" echo # :flag.usage @@ -265,13 +228,14 @@ orcli_import_csv_usage() { # :flag.usage printf " %s\n" "--headerLines HEADERLINES" printf " parse x line(s) as column headers\n" - printf " Default: 1\n" + printf " %s\n" "Default: 1" + printf " %s\n" "Conflicts: --columnNames" echo # :flag.usage printf " %s\n" "--ignoreLines IGNORELINES" printf " ignore first x line(s) at beginning of file\n" - printf " Default: -1\n" + printf " %s\n" "Default: -1" echo # :flag.usage @@ -292,13 +256,13 @@ orcli_import_csv_usage() { # :flag.usage printf " %s\n" "--limit LIMIT" printf " load at most x row(s) of data\n" - printf " Default: -1\n" + printf " %s\n" "Default: -1" echo # :flag.usage printf " %s\n" "--quoteCharacter QUOTECHARACTER" printf " quote character to enclose cells containing column separators\n" - printf " Default: \\\"\n" + printf " %s\n" "Default: \\\"" echo # :flag.usage @@ -309,7 +273,7 @@ orcli_import_csv_usage() { # :flag.usage printf " %s\n" "--skipDataLines SKIPDATALINES" printf " discard initial x row(s) of data\n" - printf " Default: 0\n" + printf " %s\n" "Default: 0" echo # :flag.usage @@ -343,7 +307,7 @@ orcli_import_csv_usage() { # :argument.usage printf " %s\n" "FILE..." printf " Path to one or more files or URLs. When FILE is -, read standard input.\n" - printf " Default: -\n" + printf " %s\n" "Default: -" echo # :command.usage_examples @@ -360,15 +324,7 @@ orcli_import_csv_usage() { # :command.usage orcli_import_tsv_usage() { - if [[ -n $long_usage ]]; then - printf "orcli import tsv - import tab-separated values (TSV)\n" - echo - - else - printf "orcli import tsv - import tab-separated values (TSV)\n" - echo - - fi + printf "orcli import tsv - import tab-separated values (TSV)\n\n" printf "%s\n" "Usage:" printf " orcli import tsv [FILE...] [OPTIONS]\n" @@ -376,7 +332,7 @@ orcli_import_tsv_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_flags @@ -388,6 +344,7 @@ orcli_import_tsv_usage() { # :flag.usage printf " %s\n" "--columnNames COLUMNNAMES" printf " set column names (comma separated)\n hint: add --ignoreLines 1 to overwrite existing header row\n" + printf " %s\n" "Conflicts: --headerLines" echo # :flag.usage @@ -403,13 +360,14 @@ orcli_import_tsv_usage() { # :flag.usage printf " %s\n" "--headerLines HEADERLINES" printf " parse x line(s) as column headers\n" - printf " Default: 1\n" + printf " %s\n" "Default: 1" + printf " %s\n" "Conflicts: --columnNames" echo # :flag.usage printf " %s\n" "--ignoreLines IGNORELINES" printf " ignore first x line(s) at beginning of file\n" - printf " Default: -1\n" + printf " %s\n" "Default: -1" echo # :flag.usage @@ -430,13 +388,13 @@ orcli_import_tsv_usage() { # :flag.usage printf " %s\n" "--limit LIMIT" printf " load at most x row(s) of data\n" - printf " Default: -1\n" + printf " %s\n" "Default: -1" echo # :flag.usage printf " %s\n" "--quoteCharacter QUOTECHARACTER" printf " quote character to enclose cells containing column separators\n" - printf " Default: \\\"\n" + printf " %s\n" "Default: \\\"" echo # :flag.usage @@ -447,7 +405,7 @@ orcli_import_tsv_usage() { # :flag.usage printf " %s\n" "--skipDataLines SKIPDATALINES" printf " discard initial x row(s) of data\n" - printf " Default: 0\n" + printf " %s\n" "Default: 0" echo # :flag.usage @@ -481,7 +439,7 @@ orcli_import_tsv_usage() { # :argument.usage printf " %s\n" "FILE..." printf " Path to one or more files or URLs. When FILE is -, read standard input.\n" - printf " Default: -\n" + printf " %s\n" "Default: -" echo # :command.usage_examples @@ -498,15 +456,7 @@ orcli_import_tsv_usage() { # :command.usage orcli_import_json_usage() { - if [[ -n $long_usage ]]; then - printf "orcli import json - import JSON\n" - echo - - else - printf "orcli import json - import JSON\n" - echo - - fi + printf "orcli import json - import JSON\n\n" printf "%s\n" "Usage:" printf " orcli import json [FILE...] [OPTIONS]\n" @@ -514,14 +464,14 @@ orcli_import_json_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_flags # :flag.usage printf " %s\n" "--recordPath JSON" printf " specify record path elements in JSON array\n" - printf " Default: [ \"_\" , \"_\" ]\n" + printf " %s\n" "Default: [ \"_\" , \"_\" ]" echo # :flag.usage @@ -547,7 +497,7 @@ orcli_import_json_usage() { # :flag.usage printf " %s\n" "--limit LIMIT" printf " load at most x row(s) of data\n" - printf " Default: -1\n" + printf " %s\n" "Default: -1" echo # :flag.usage @@ -586,7 +536,7 @@ orcli_import_json_usage() { # :argument.usage printf " %s\n" "FILE..." printf " Path to one or more files or URLs. When FILE is -, read standard input.\n" - printf " Default: -\n" + printf " %s\n" "Default: -" echo # :command.usage_examples @@ -602,15 +552,7 @@ orcli_import_json_usage() { # :command.usage orcli_import_jsonl_usage() { - if [[ -n $long_usage ]]; then - printf "orcli import jsonl - import JSON Lines / newline-delimited JSON\n" - echo - - else - printf "orcli import jsonl - import JSON Lines / newline-delimited JSON\n" - echo - - fi + printf "orcli import jsonl - import JSON Lines / newline-delimited JSON\n\n" printf "%s\n" "Usage:" printf " orcli import jsonl [FILE...] [OPTIONS]\n" @@ -618,7 +560,7 @@ orcli_import_jsonl_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_flags @@ -645,7 +587,7 @@ orcli_import_jsonl_usage() { # :flag.usage printf " %s\n" "--limit LIMIT" printf " load at most x row(s) of data\n" - printf " Default: -1\n" + printf " %s\n" "Default: -1" echo # :flag.usage @@ -684,7 +626,7 @@ orcli_import_jsonl_usage() { # :argument.usage printf " %s\n" "FILE..." printf " Path to one or more files or URLs. When FILE is -, read standard input.\n" - printf " Default: -\n" + printf " %s\n" "Default: -" echo # :command.usage_examples @@ -701,15 +643,7 @@ orcli_import_jsonl_usage() { # :command.usage orcli_list_usage() { - if [[ -n $long_usage ]]; then - printf "orcli list - list projects on OpenRefine server\n" - echo - - else - printf "orcli list - list projects on OpenRefine server\n" - echo - - fi + printf "orcli list - list projects on OpenRefine server\n\n" printf "%s\n" "Usage:" printf " orcli list\n" @@ -717,7 +651,7 @@ orcli_list_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_fixed_flags @@ -730,15 +664,7 @@ orcli_list_usage() { # :command.usage orcli_info_usage() { - if [[ -n $long_usage ]]; then - printf "orcli info - show OpenRefine project's metadata\n" - echo - - else - printf "orcli info - show OpenRefine project's metadata\n" - echo - - fi + printf "orcli info - show OpenRefine project's metadata\n\n" printf "%s\n" "Usage:" printf " orcli info PROJECT\n" @@ -746,7 +672,7 @@ orcli_info_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_fixed_flags @@ -775,16 +701,10 @@ orcli_info_usage() { # :command.usage orcli_search_usage() { if [[ -n $long_usage ]]; then - printf "orcli search\n" - echo - - printf " apply regex to each column and print matches in flattened tsv format\n output: index column value\n note that any exporter supports search by using --facets (see examples)\n" - echo - + printf "orcli search\n\n" + printf " apply regex to each column and print matches in flattened tsv format\n output: index column value\n note that any exporter supports search by using --facets (see examples)\n\n" else - printf "orcli search - apply regex to each column and print matches in flattened tsv format\n" - echo - + printf "orcli search - apply regex to each column and print matches in flattened tsv format\n\n" fi printf "%s\n" "Usage:" @@ -793,7 +713,7 @@ orcli_search_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_flags @@ -835,15 +755,7 @@ orcli_search_usage() { # :command.usage orcli_sort_usage() { - if [[ -n $long_usage ]]; then - printf "orcli sort - commands to sort OpenRefine projects\n" - echo - - else - printf "orcli sort - commands to sort OpenRefine projects\n" - echo - - fi + printf "orcli sort - commands to sort OpenRefine projects\n\n" printf "%s\n" "Usage:" printf " orcli sort COMMAND\n" @@ -855,7 +767,7 @@ orcli_sort_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_fixed_flags @@ -868,15 +780,7 @@ orcli_sort_usage() { # :command.usage orcli_sort_columns_usage() { - if [[ -n $long_usage ]]; then - printf "orcli sort columns - re-order columns alphabetically\n" - echo - - else - printf "orcli sort columns - re-order columns alphabetically\n" - echo - - fi + printf "orcli sort columns - re-order columns alphabetically\n\n" printf "%s\n" "Usage:" printf " orcli sort columns PROJECT [OPTIONS]\n" @@ -884,7 +788,7 @@ orcli_sort_columns_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_flags @@ -917,15 +821,7 @@ orcli_sort_columns_usage() { # :command.usage orcli_test_usage() { - if [[ -n $long_usage ]]; then - printf "orcli test - run functional tests on tmp OpenRefine workspace\n" - echo - - else - printf "orcli test - run functional tests on tmp OpenRefine workspace\n" - echo - - fi + printf "orcli test - run functional tests on tmp OpenRefine workspace\n\n" printf "%s\n" "Usage:" printf " orcli test\n" @@ -933,7 +829,7 @@ orcli_test_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_fixed_flags @@ -946,15 +842,7 @@ orcli_test_usage() { # :command.usage orcli_transform_usage() { - if [[ -n $long_usage ]]; then - printf "orcli transform - apply undo/redo JSON file(s) to an OpenRefine project\n" - echo - - else - printf "orcli transform - apply undo/redo JSON file(s) to an OpenRefine project\n" - echo - - fi + printf "orcli transform - apply undo/redo JSON file(s) to an OpenRefine project\n\n" printf "%s\n" "Usage:" printf " orcli transform PROJECT [FILE...] [OPTIONS]\n" @@ -962,7 +850,7 @@ orcli_transform_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_flags @@ -987,7 +875,7 @@ orcli_transform_usage() { # :argument.usage printf " %s\n" "FILE..." printf " Path to one or more files or URLs. When FILE is -, read standard input.\n" - printf " Default: -\n" + printf " %s\n" "Default: -" echo # :command.usage_examples @@ -1003,15 +891,7 @@ orcli_transform_usage() { # :command.usage orcli_export_usage() { - if [[ -n $long_usage ]]; then - printf "orcli export - commands to export data from OpenRefine projects to files\n" - echo - - else - printf "orcli export - commands to export data from OpenRefine projects to files\n" - echo - - fi + printf "orcli export - commands to export data from OpenRefine projects to files\n\n" printf "%s\n" "Usage:" printf " orcli export COMMAND\n" @@ -1026,7 +906,7 @@ orcli_export_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_fixed_flags @@ -1039,15 +919,7 @@ orcli_export_usage() { # :command.usage orcli_export_jsonl_usage() { - if [[ -n $long_usage ]]; then - printf "orcli export jsonl - export JSON Lines / newline-delimited JSON\n" - echo - - else - printf "orcli export jsonl - export JSON Lines / newline-delimited JSON\n" - echo - - fi + printf "orcli export jsonl - export JSON Lines / newline-delimited JSON\n\n" printf "%s\n" "Usage:" printf " orcli export jsonl PROJECT [OPTIONS]\n" @@ -1055,15 +927,15 @@ orcli_export_jsonl_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_flags # :flag.usage printf " %s\n" "--mode MODE" printf " specify if project contains multi-row records\n" - printf " Allowed: rows, records\n" - printf " Default: rows\n" + printf " %s\n" "Allowed: rows, records" + printf " %s\n" "Default: rows" echo # :flag.usage @@ -1074,7 +946,7 @@ orcli_export_jsonl_usage() { # :flag.usage printf " %s\n" "--facets FACETS" printf " filter result set by providing an OpenRefine facets config in json\n" - printf " Default: []\n" + printf " %s\n" "Default: []" echo # :flag.usage @@ -1085,7 +957,7 @@ orcli_export_jsonl_usage() { # :flag.usage printf " %s\n" "--encoding ENCODING" printf " set character encoding\n" - printf " Default: UTF-8\n" + printf " %s\n" "Default: UTF-8" echo # :flag.usage @@ -1121,15 +993,7 @@ orcli_export_jsonl_usage() { # :command.usage orcli_export_csv_usage() { - if [[ -n $long_usage ]]; then - printf "orcli export csv - export comma-separated values (CSV)\n" - echo - - else - printf "orcli export csv - export comma-separated values (CSV)\n" - echo - - fi + printf "orcli export csv - export comma-separated values (CSV)\n\n" printf "%s\n" "Usage:" printf " orcli export csv PROJECT [OPTIONS]\n" @@ -1137,14 +1001,14 @@ orcli_export_csv_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_flags # :flag.usage printf " %s\n" "--separator SEPARATOR" printf " character(s) that separates columns\n" - printf " Default: ,\n" + printf " %s\n" "Default: ," echo # :flag.usage @@ -1155,14 +1019,14 @@ orcli_export_csv_usage() { # :flag.usage printf " %s\n" "--mode MODE" printf " specify if project contains multi-row records\n" - printf " Allowed: rows, records\n" - printf " Default: rows\n" + printf " %s\n" "Allowed: rows, records" + printf " %s\n" "Default: rows" echo # :flag.usage printf " %s\n" "--facets FACETS" printf " filter result set by providing an OpenRefine facets config in json\n" - printf " Default: []\n" + printf " %s\n" "Default: []" echo # :flag.usage @@ -1173,7 +1037,7 @@ orcli_export_csv_usage() { # :flag.usage printf " %s\n" "--encoding ENCODING" printf " set character encoding\n" - printf " Default: UTF-8\n" + printf " %s\n" "Default: UTF-8" echo # :flag.usage @@ -1210,15 +1074,7 @@ orcli_export_csv_usage() { # :command.usage orcli_export_tsv_usage() { - if [[ -n $long_usage ]]; then - printf "orcli export tsv - export tab-separated values (TSV)\n" - echo - - else - printf "orcli export tsv - export tab-separated values (TSV)\n" - echo - - fi + printf "orcli export tsv - export tab-separated values (TSV)\n\n" printf "%s\n" "Usage:" printf " orcli export tsv PROJECT [OPTIONS]\n" @@ -1226,7 +1082,7 @@ orcli_export_tsv_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_flags @@ -1238,14 +1094,14 @@ orcli_export_tsv_usage() { # :flag.usage printf " %s\n" "--mode MODE" printf " specify if project contains multi-row records\n" - printf " Allowed: rows, records\n" - printf " Default: rows\n" + printf " %s\n" "Allowed: rows, records" + printf " %s\n" "Default: rows" echo # :flag.usage printf " %s\n" "--facets FACETS" printf " filter result set by providing an OpenRefine facets config in json\n" - printf " Default: []\n" + printf " %s\n" "Default: []" echo # :flag.usage @@ -1256,7 +1112,7 @@ orcli_export_tsv_usage() { # :flag.usage printf " %s\n" "--encoding ENCODING" printf " set character encoding\n" - printf " Default: UTF-8\n" + printf " %s\n" "Default: UTF-8" echo # :flag.usage @@ -1292,15 +1148,7 @@ orcli_export_tsv_usage() { # :command.usage orcli_export_template_usage() { - if [[ -n $long_usage ]]; then - printf "orcli export template - export to any text format by providing your own GREL template\n" - echo - - else - printf "orcli export template - export to any text format by providing your own GREL template\n" - echo - - fi + printf "orcli export template - export to any text format by providing your own GREL template\n\n" printf "%s\n" "Usage:" printf " orcli export template PROJECT [FILE] [OPTIONS]\n" @@ -1308,7 +1156,7 @@ orcli_export_template_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_flags @@ -1330,14 +1178,14 @@ orcli_export_template_usage() { # :flag.usage printf " %s\n" "--mode MODE" printf " specify if project contains multi-row records\n" - printf " Allowed: rows, records\n" - printf " Default: rows\n" + printf " %s\n" "Allowed: rows, records" + printf " %s\n" "Default: rows" echo # :flag.usage printf " %s\n" "--facets FACETS" printf " filter result set by providing an OpenRefine facets config in json\n" - printf " Default: []\n" + printf " %s\n" "Default: []" echo # :flag.usage @@ -1348,7 +1196,7 @@ orcli_export_template_usage() { # :flag.usage printf " %s\n" "--encoding ENCODING" printf " set character encoding\n" - printf " Default: UTF-8\n" + printf " %s\n" "Default: UTF-8" echo # :flag.usage @@ -1372,7 +1220,7 @@ orcli_export_template_usage() { # :argument.usage printf " %s\n" "FILE" printf " Path to row/record template file or URL. When FILE is -, read standard\n input.\n" - printf " Default: -\n" + printf " %s\n" "Default: -" echo # :command.usage_examples @@ -1389,15 +1237,7 @@ orcli_export_template_usage() { # :command.usage orcli_run_usage() { - if [[ -n $long_usage ]]; then - printf "orcli run - run tmp OpenRefine workspace and execute shell script(s)\n" - echo - - else - printf "orcli run - run tmp OpenRefine workspace and execute shell script(s)\n" - echo - - fi + printf "orcli run - run tmp OpenRefine workspace and execute shell script(s)\n\n" printf "%s\n" "Usage:" printf " orcli run [FILE...] [OPTIONS]\n" @@ -1405,20 +1245,20 @@ orcli_run_usage() { echo # :command.long_usage - if [[ -n $long_usage ]]; then + if [[ -n "$long_usage" ]]; then printf "%s\n" "Options:" # :command.usage_flags # :flag.usage printf " %s\n" "--memory RAM" printf " maximum RAM for OpenRefine java heap space\n" - printf " Default: 2048M\n" + printf " %s\n" "Default: 2048M" echo # :flag.usage printf " %s\n" "--port PORT" printf " PORT on which OpenRefine should listen\n" - printf " Default: 3333\n" + printf " %s\n" "Default: 3333" echo # :flag.usage @@ -1442,27 +1282,31 @@ orcli_run_usage() { # :argument.usage printf " %s\n" "FILE..." printf " Path to one or more files or URLs. When FILE is -, read standard input.\n" - printf " Default: -\n" + printf " %s\n" "Default: -" echo # :command.usage_examples printf "%s\n" "Examples:" printf " orcli run --interactive\n" - printf " orcli run << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\"\n orcli transform \"duplicates\" \"https://git.io/fj5ju\"\n orcli export tsv \"duplicates\"\n EOF\n" - printf " orcli run --memory \"2000M\" --port \"3334\" << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\" &\n orcli import csv \"https://git.io/fj5hF\" --projectName \"copy\" &\n wait\n echo \"finished import\"\n orcli export csv \"duplicates\" --output duplicates.csv &\n orcli export tsv \"duplicates\" --output duplicates.tsv &\n wait\n wc duplicates*\n EOF\n" - printf " orcli run --interactive \"file1.sh\" \"file2.sh\" - << EOF\n echo \"finished in \$SECONDS seconds\"\n EOF\n" - echo + printf " orcli run << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\"\n orcli transform \"duplicates\" \"https://git.io/fj5ju\"\n orcli export tsv \"duplicates\"\nEOF\n" +printf " orcli run --memory \"2000M\" --port \"3334\" << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\" &\n orcli import csv \"https://git.io/fj5hF\" --projectName \"copy\" &\n wait\n echo \"finished import\"\n orcli export csv \"duplicates\" --output duplicates.csv &\n orcli export tsv \"duplicates\" --output duplicates.tsv &\n wait\n wc duplicates*\nEOF\n" +printf " orcli run --interactive \"file1.sh\" \"file2.sh\" - << EOF\n echo \"finished in \$SECONDS seconds\"\nEOF\n" +echo - fi +fi } # :command.normalize_input +# :command.normalize_input_function normalize_input() { - local arg flags + local arg passthru flags + passthru=false while [[ $# -gt 0 ]]; do arg="$1" - if [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then + if [[ $passthru == true ]]; then + input+=("$arg") + elif [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then input+=("${BASH_REMATCH[1]}") input+=("${BASH_REMATCH[2]}") elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then @@ -1473,6 +1317,9 @@ normalize_input() { for ((i = 0; i < ${#flags}; i++)); do input+=("-${flags:i:1}") done + elif [[ "$arg" == "--" ]]; then + passthru=true + input+=("$arg") else input+=("$arg") fi @@ -1480,12 +1327,15 @@ normalize_input() { shift done } + # :command.inspect_args inspect_args() { if ((${#args[@]})); then readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) echo args: - for k in "${sorted_keys[@]}"; do echo "- \${args[$k]} = ${args[$k]}"; done + for k in "${sorted_keys[@]}"; do + echo "- \${args[$k]} = ${args[$k]}" + done else echo args: none fi @@ -1503,9 +1353,19 @@ inspect_args() { readarray -t sorted_keys < <(printf '%s\n' "${!deps[@]}" | sort) echo echo deps: - for k in "${sorted_keys[@]}"; do echo "- \${deps[$k]} = ${deps[$k]}"; done + for k in "${sorted_keys[@]}"; do + echo "- \${deps[$k]} = ${deps[$k]}" + done fi + if ((${#env_var_names[@]})); then + readarray -t sorted_names < <(printf '%s\n' "${env_var_names[@]}" | sort) + echo + echo "environment variables:" + for k in "${sorted_names[@]}"; do + echo "- \$$k = ${!k:-}" + done + fi } # :command.user_lib @@ -1657,7 +1517,7 @@ function post_export() { curloptions+=("--output" "${args[--output]}") fi # post - if ! curl -fs "${curloptions[@]}" "${OPENREFINE_URL}/command/core/export-rows"; then + if ! curl -fs "${curloptions[@]}" "${OPENREFINE_URL}/command/core/export-rows$(get_csrf)"; then error "exporting ${args[project]} failed!" else if [[ ${args[--output]} ]]; then @@ -1739,7 +1599,7 @@ send_completions() { echo $'' echo $' if [[ "${cur:0:1}" == "-" ]]; then' echo $' echo "$words"' - echo $' ' + echo $'' echo $' else' echo $' for word in $words; do' echo $' [[ "${word:0:1}" != "-" ]] && result+=("$word")' @@ -1757,108 +1617,108 @@ send_completions() { echo $'' echo $' case "$compline" in' echo $' \'export template\'*\'--mode\')' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur")' echo $' ;;' echo $'' echo $' \'export jsonl\'*\'--mode\')' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'export csv\'*\'--mode\')' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur")' echo $' ;;' echo $'' echo $' \'export tsv\'*\'--mode\')' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'export csv\'*\'--mode\')' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur")' echo $' ;;' echo $'' echo $' \'export template\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --prefix --quiet --separator --suffix -h -q")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'import jsonl\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--guessCellValueTypes --help --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --rename --storeEmptyStrings --trimStrings -h -q")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'sort columns\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--first --help -h")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --prefix --quiet --separator --suffix -h -q")" -- "$cur")' echo $' ;;' echo $'' echo $' \'export jsonl\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet --separator -h -q")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet --separator -h -q")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'sort columns\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--first --help -h")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'import jsonl\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--guessCellValueTypes --help --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --rename --storeEmptyStrings --trimStrings -h -q")" -- "$cur")' echo $' ;;' echo $'' echo $' \'completions\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur")' echo $' ;;' echo $'' echo $' \'import json\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--guessCellValueTypes --help --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --recordPath --rename --storeEmptyStrings --trimStrings -h -q")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'import csv\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--blankCellsAsStrings --columnNames --encoding --guessCellValueTypes --headerLines --help --ignoreLines --ignoreQuoteCharacter --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --quoteCharacter --separator --skipBlankRows --skipDataLines --trimStrings -h -q")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'import tsv\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--blankCellsAsStrings --columnNames --encoding --guessCellValueTypes --headerLines --help --ignoreLines --ignoreQuoteCharacter --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --quoteCharacter --skipBlankRows --skipDataLines --trimStrings -h -q")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'export csv\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet --select --separator -h -q")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--guessCellValueTypes --help --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --recordPath --rename --storeEmptyStrings --trimStrings -h -q")" -- "$cur")' echo $' ;;' echo $'' echo $' \'export tsv\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet --select -h -q")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet --select -h -q")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'export csv\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet --select --separator -h -q")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'import csv\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--blankCellsAsStrings --columnNames --encoding --guessCellValueTypes --headerLines --help --ignoreLines --ignoreQuoteCharacter --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --quoteCharacter --separator --skipBlankRows --skipDataLines --trimStrings -h -q")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'import tsv\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--blankCellsAsStrings --columnNames --encoding --guessCellValueTypes --headerLines --help --ignoreLines --ignoreQuoteCharacter --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --quoteCharacter --skipBlankRows --skipDataLines --trimStrings -h -q")" -- "$cur")' echo $' ;;' echo $'' echo $' \'transform\'*)' - 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 "--help --quiet -h -q")" -- "$cur")' echo $' ;;' echo $'' echo $' \'delete\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--force --help --quiet -f -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 $' \'import\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h csv json jsonl tsv")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'search\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --index -h")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help -h csv json jsonl tsv")" -- "$cur")' echo $' ;;' echo $'' echo $' \'export\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h csv jsonl template tsv")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help -h csv jsonl template tsv")" -- "$cur")' echo $' ;;' echo $'' - echo $' \'list\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'info\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'sort\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h columns")" -- "$cur" )' + echo $' \'search\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help --index -h")" -- "$cur")' echo $' ;;' echo $'' echo $' \'test\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'sort\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help -h columns")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'info\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'list\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur")' echo $' ;;' echo $'' echo $' \'run\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --interactive --memory --port --quiet -h -q")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help --interactive --memory --port --quiet -h -q")" -- "$cur")' echo $' ;;' echo $'' echo $' *)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --version -h -v completions delete export import info list run search sort test transform")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help --version -h -v completions delete export import info list run search sort test transform")" -- "$cur")' echo $' ;;' echo $'' echo $' esac' echo $'} &&' - echo $'complete -F _orcli_completions orcli' + echo $' complete -F _orcli_completions orcli' echo $'' echo $'# ex: filetype=sh' } @@ -1866,6 +1726,7 @@ send_completions() { # :command.command_functions # :command.function orcli_completions_command() { + # src/completions_command.sh # Users can now enable bash completion for this script by running: # @@ -1876,6 +1737,7 @@ orcli_completions_command() { # :command.function orcli_delete_command() { + # src/delete_command.sh # shellcheck shell=bash disable=SC2154 @@ -1905,6 +1767,7 @@ orcli_delete_command() { # :command.function orcli_import_csv_command() { + # src/import_csv_command.sh # shellcheck shell=bash disable=SC2154 @@ -1997,6 +1860,7 @@ orcli_import_csv_command() { # :command.function orcli_import_tsv_command() { + # src/import_tsv_command.sh # shellcheck shell=bash disable=SC2154 @@ -2089,6 +1953,7 @@ orcli_import_tsv_command() { # :command.function orcli_import_json_command() { + # src/import_json_command.sh # shellcheck shell=bash disable=SC2154 @@ -2148,6 +2013,7 @@ orcli_import_json_command() { # :command.function orcli_import_jsonl_command() { + # src/import_jsonl_command.sh # shellcheck shell=bash disable=SC2154 @@ -2207,6 +2073,7 @@ orcli_import_jsonl_command() { # :command.function orcli_list_command() { + # src/list_command.sh # get all project metadata and reshape json to print a list # shellcheck shell=bash @@ -2224,6 +2091,7 @@ orcli_list_command() { # :command.function orcli_info_command() { + # src/info_command.sh # shellcheck shell=bash disable=SC2154 @@ -2241,6 +2109,7 @@ orcli_info_command() { # :command.function orcli_search_command() { + # src/search_command.sh # shellcheck shell=bash disable=SC2154 @@ -2281,6 +2150,7 @@ orcli_search_command() { # :command.function orcli_sort_columns_command() { + # src/sort_columns_command.sh # get columns, sort and transform with re-order columns # shellcheck shell=bash @@ -2306,6 +2176,7 @@ orcli_sort_columns_command() { # :command.function orcli_test_command() { + # src/test_command.sh # shellcheck shell=bash disable=SC2154 @@ -2388,6 +2259,7 @@ orcli_test_command() { # :command.function orcli_transform_command() { + # src/transform_command.sh # shellcheck shell=bash disable=SC2154 disable=SC2155 @@ -2501,6 +2373,7 @@ orcli_transform_command() { # :command.function orcli_export_jsonl_command() { + # src/export_jsonl_command.sh # shellcheck shell=bash disable=SC2154 disable=SC2155 projectid="$(get_id "${args[project]}")" @@ -2515,7 +2388,7 @@ orcli_export_jsonl_command() { if [[ ${args[--mode]} == "records" ]]; then engine='{"facets":[{"type":"list","columnName":"","expression":"grel:filter(row.columnNames,cn,row.record.cells[cn].value.length()>1)","selection":[]}],"mode":"row-based"}' fi - readarray -t columns_mv < <(curl -fs --data project="$projectid" --data "engine=${engine}" "${OPENREFINE_URL}/command/core/compute-facets" | jq -r '.facets[].choices[].v.v') + readarray -t columns_mv < <(curl -fs --data project="$projectid" --data "engine=${engine}" "${OPENREFINE_URL}/command/core/compute-facets$(get_csrf)" | jq -r '.facets[].choices[].v.v') readarray -t columns < <(curl -fs --get --data project="$projectid" "${OPENREFINE_URL}/command/core/get-columns-info" | jq -r '.[].name') readarray -t columns_mix < <(for i in "${columns[@]}"; do skip= @@ -2577,6 +2450,7 @@ orcli_export_jsonl_command() { # :command.function orcli_export_csv_command() { + # src/export_csv_command.sh # shellcheck shell=bash projectid="$(get_id "${args[project]}")" @@ -2616,6 +2490,7 @@ orcli_export_csv_command() { # :command.function orcli_export_tsv_command() { + # src/export_tsv_command.sh # shellcheck shell=bash projectid="$(get_id "${args[project]}")" @@ -2655,6 +2530,7 @@ orcli_export_tsv_command() { # :command.function orcli_export_template_command() { + # src/export_template_command.sh # shellcheck shell=bash disable=SC2154 disable=SC2155 @@ -2711,6 +2587,7 @@ orcli_export_template_command() { # :command.function orcli_run_command() { + # src/run_command.sh # shellcheck shell=bash disable=SC2154 source=/dev/null @@ -2824,7 +2701,8 @@ orcli_run_command() { parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --version | -v) version_command exit @@ -2847,6 +2725,8 @@ parse_requirements() { # :command.environment_variables_default export OPENREFINE_URL="${OPENREFINE_URL:-http://localhost:3333}" + env_var_names+=("OPENREFINE_URL") + # :command.dependencies_filter if command -v curl >/dev/null 2>&1; then deps['curl']="$(command -v curl | head -n1)" @@ -2987,7 +2867,8 @@ parse_requirements() { orcli_completions_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_completions_usage @@ -3031,7 +2912,8 @@ orcli_completions_parse_requirements() { orcli_delete_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_delete_usage @@ -3076,8 +2958,8 @@ orcli_delete_parse_requirements() { *) # :command.parse_requirements_case # :command.parse_requirements_case_simple + # :argument.case if [[ -z ${args['project']+x} ]]; then - args['project']=$1 shift else @@ -3089,10 +2971,10 @@ orcli_delete_parse_requirements() { esac done - # :command.required_args_filter if [[ -z ${args['project']+x} ]]; then printf "missing required argument: PROJECT\nusage: orcli delete PROJECT [OPTIONS]\n" >&2 + exit 1 fi @@ -3102,7 +2984,8 @@ orcli_delete_parse_requirements() { orcli_import_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_import_usage @@ -3190,7 +3073,8 @@ orcli_import_parse_requirements() { orcli_import_csv_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_import_csv_usage @@ -3216,7 +3100,6 @@ orcli_import_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--separator']="$2" shift shift @@ -3244,7 +3127,6 @@ orcli_import_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--columnNames']="$2" shift shift @@ -3259,7 +3141,6 @@ orcli_import_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--encoding']="$2" shift shift @@ -3287,7 +3168,6 @@ orcli_import_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--headerLines']="$2" shift shift @@ -3302,7 +3182,6 @@ orcli_import_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--ignoreLines']="$2" shift shift @@ -3341,7 +3220,6 @@ orcli_import_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--limit']="$2" shift shift @@ -3356,7 +3234,6 @@ orcli_import_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--quoteCharacter']="$2" shift shift @@ -3379,7 +3256,6 @@ orcli_import_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--skipDataLines']="$2" shift shift @@ -3402,7 +3278,6 @@ orcli_import_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--projectName']="$2" shift shift @@ -3417,7 +3292,6 @@ orcli_import_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--projectTags']="$2" shift shift @@ -3443,14 +3317,15 @@ orcli_import_csv_parse_requirements() { *) # :command.parse_requirements_case # :command.parse_requirements_case_repeatable - + # :argument.case_repeatable + escaped="$(printf '%q' "$1")" if [[ -z ${args['file']+x} ]]; then - args['file']="\"$1\"" - shift + args['file']="$escaped" else - args['file']="${args[file]} \"$1\"" - shift + args['file']="${args['file']} $escaped" + fi + shift ;; @@ -3472,7 +3347,8 @@ orcli_import_csv_parse_requirements() { orcli_import_tsv_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_import_tsv_usage @@ -3511,7 +3387,6 @@ orcli_import_tsv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--columnNames']="$2" shift shift @@ -3526,7 +3401,6 @@ orcli_import_tsv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--encoding']="$2" shift shift @@ -3554,7 +3428,6 @@ orcli_import_tsv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--headerLines']="$2" shift shift @@ -3569,7 +3442,6 @@ orcli_import_tsv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--ignoreLines']="$2" shift shift @@ -3608,7 +3480,6 @@ orcli_import_tsv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--limit']="$2" shift shift @@ -3623,7 +3494,6 @@ orcli_import_tsv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--quoteCharacter']="$2" shift shift @@ -3646,7 +3516,6 @@ orcli_import_tsv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--skipDataLines']="$2" shift shift @@ -3669,7 +3538,6 @@ orcli_import_tsv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--projectName']="$2" shift shift @@ -3684,7 +3552,6 @@ orcli_import_tsv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--projectTags']="$2" shift shift @@ -3710,14 +3577,15 @@ orcli_import_tsv_parse_requirements() { *) # :command.parse_requirements_case # :command.parse_requirements_case_repeatable - + # :argument.case_repeatable + escaped="$(printf '%q' "$1")" if [[ -z ${args['file']+x} ]]; then - args['file']="\"$1\"" - shift + args['file']="$escaped" else - args['file']="${args[file]} \"$1\"" - shift + args['file']="${args['file']} $escaped" + fi + shift ;; @@ -3738,7 +3606,8 @@ orcli_import_tsv_parse_requirements() { orcli_import_json_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_import_json_usage @@ -3764,7 +3633,6 @@ orcli_import_json_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--recordPath']="$2" shift shift @@ -3811,7 +3679,6 @@ orcli_import_json_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--limit']="$2" shift shift @@ -3842,7 +3709,6 @@ orcli_import_json_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--projectName']="$2" shift shift @@ -3857,7 +3723,6 @@ orcli_import_json_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--projectTags']="$2" shift shift @@ -3883,14 +3748,15 @@ orcli_import_json_parse_requirements() { *) # :command.parse_requirements_case # :command.parse_requirements_case_repeatable - + # :argument.case_repeatable + escaped="$(printf '%q' "$1")" if [[ -z ${args['file']+x} ]]; then - args['file']="\"$1\"" - shift + args['file']="$escaped" else - args['file']="${args[file]} \"$1\"" - shift + args['file']="${args['file']} $escaped" + fi + shift ;; @@ -3908,7 +3774,8 @@ orcli_import_json_parse_requirements() { orcli_import_jsonl_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_import_jsonl_usage @@ -3966,7 +3833,6 @@ orcli_import_jsonl_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--limit']="$2" shift shift @@ -3997,7 +3863,6 @@ orcli_import_jsonl_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--projectName']="$2" shift shift @@ -4012,7 +3877,6 @@ orcli_import_jsonl_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--projectTags']="$2" shift shift @@ -4038,14 +3902,15 @@ orcli_import_jsonl_parse_requirements() { *) # :command.parse_requirements_case # :command.parse_requirements_case_repeatable - + # :argument.case_repeatable + escaped="$(printf '%q' "$1")" if [[ -z ${args['file']+x} ]]; then - args['file']="\"$1\"" - shift + args['file']="$escaped" else - args['file']="${args[file]} \"$1\"" - shift + args['file']="${args['file']} $escaped" + fi + shift ;; @@ -4062,7 +3927,8 @@ orcli_import_jsonl_parse_requirements() { orcli_list_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_list_usage @@ -4106,7 +3972,8 @@ orcli_list_parse_requirements() { orcli_info_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_info_usage @@ -4136,8 +4003,8 @@ orcli_info_parse_requirements() { *) # :command.parse_requirements_case # :command.parse_requirements_case_simple + # :argument.case if [[ -z ${args['project']+x} ]]; then - args['project']=$1 shift else @@ -4149,10 +4016,10 @@ orcli_info_parse_requirements() { esac done - # :command.required_args_filter if [[ -z ${args['project']+x} ]]; then printf "missing required argument: PROJECT\nusage: orcli info PROJECT\n" >&2 + exit 1 fi @@ -4162,7 +4029,8 @@ orcli_info_parse_requirements() { orcli_search_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_search_usage @@ -4188,7 +4056,6 @@ orcli_search_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--index']="$2" shift shift @@ -4206,12 +4073,12 @@ orcli_search_parse_requirements() { *) # :command.parse_requirements_case # :command.parse_requirements_case_simple + # :argument.case if [[ -z ${args['project']+x} ]]; then - args['project']=$1 shift + # :argument.case elif [[ -z ${args['regex']+x} ]]; then - args['regex']=$1 shift else @@ -4223,10 +4090,10 @@ orcli_search_parse_requirements() { esac done - # :command.required_args_filter if [[ -z ${args['project']+x} ]]; then printf "missing required argument: PROJECT\nusage: orcli search PROJECT [REGEX] [OPTIONS]\n" >&2 + exit 1 fi @@ -4236,7 +4103,8 @@ orcli_search_parse_requirements() { orcli_sort_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_sort_usage @@ -4303,7 +4171,8 @@ orcli_sort_parse_requirements() { orcli_sort_columns_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_sort_columns_usage @@ -4329,11 +4198,11 @@ orcli_sort_columns_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - + escaped="$(printf '%q' "$2")" if [[ -z ${args['--first']+x} ]]; then - args['--first']="\"$2\"" + args['--first']="$escaped" else - args['--first']="${args[--first]} \"$2\"" + args['--first']="${args['--first']} $escaped" fi shift shift @@ -4351,8 +4220,8 @@ orcli_sort_columns_parse_requirements() { *) # :command.parse_requirements_case # :command.parse_requirements_case_simple + # :argument.case if [[ -z ${args['project']+x} ]]; then - args['project']=$1 shift else @@ -4364,10 +4233,10 @@ orcli_sort_columns_parse_requirements() { esac done - # :command.required_args_filter if [[ -z ${args['project']+x} ]]; then printf "missing required argument: PROJECT\nusage: orcli sort columns PROJECT [OPTIONS]\n" >&2 + exit 1 fi @@ -4377,7 +4246,8 @@ orcli_sort_columns_parse_requirements() { orcli_test_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_test_usage @@ -4421,7 +4291,8 @@ orcli_test_parse_requirements() { orcli_transform_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_transform_usage @@ -4458,27 +4329,28 @@ orcli_transform_parse_requirements() { *) # :command.parse_requirements_case # :command.parse_requirements_case_repeatable - + # :argument.case_repeatable + escaped="$(printf '%q' "$1")" if [[ -z ${args['project']+x} ]]; then - args['project']=$1 - shift + args['project']="$1" + # :argument.case_repeatable elif [[ -z ${args['file']+x} ]]; then - args['file']="\"$1\"" - shift + args['file']="$escaped" else - args['file']="${args[file]} \"$1\"" - shift + args['file']="${args['file']} $escaped" + fi + shift ;; esac done - # :command.required_args_filter if [[ -z ${args['project']+x} ]]; then printf "missing required argument: PROJECT\nusage: orcli transform PROJECT [FILE...] [OPTIONS]\n" >&2 + exit 1 fi @@ -4491,7 +4363,8 @@ orcli_transform_parse_requirements() { orcli_export_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_export_usage @@ -4579,7 +4452,8 @@ orcli_export_parse_requirements() { orcli_export_jsonl_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_export_jsonl_usage @@ -4605,7 +4479,6 @@ orcli_export_jsonl_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--mode']="$2" shift shift @@ -4620,7 +4493,6 @@ orcli_export_jsonl_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--separator']="$2" shift shift @@ -4635,7 +4507,6 @@ orcli_export_jsonl_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--facets']="$2" shift shift @@ -4650,7 +4521,6 @@ orcli_export_jsonl_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--output']="$2" shift shift @@ -4665,7 +4535,6 @@ orcli_export_jsonl_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--encoding']="$2" shift shift @@ -4691,8 +4560,8 @@ orcli_export_jsonl_parse_requirements() { *) # :command.parse_requirements_case # :command.parse_requirements_case_simple + # :argument.case if [[ -z ${args['project']+x} ]]; then - args['project']=$1 shift else @@ -4704,10 +4573,10 @@ orcli_export_jsonl_parse_requirements() { esac done - # :command.required_args_filter if [[ -z ${args['project']+x} ]]; then printf "missing required argument: PROJECT\nusage: orcli export jsonl PROJECT [OPTIONS]\n" >&2 + exit 1 fi @@ -4728,7 +4597,8 @@ orcli_export_jsonl_parse_requirements() { orcli_export_csv_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_export_csv_usage @@ -4754,7 +4624,6 @@ orcli_export_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--separator']="$2" shift shift @@ -4769,7 +4638,6 @@ orcli_export_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--select']="$2" shift shift @@ -4784,7 +4652,6 @@ orcli_export_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--mode']="$2" shift shift @@ -4799,7 +4666,6 @@ orcli_export_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--facets']="$2" shift shift @@ -4814,7 +4680,6 @@ orcli_export_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--output']="$2" shift shift @@ -4829,7 +4694,6 @@ orcli_export_csv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--encoding']="$2" shift shift @@ -4855,8 +4719,8 @@ orcli_export_csv_parse_requirements() { *) # :command.parse_requirements_case # :command.parse_requirements_case_simple + # :argument.case if [[ -z ${args['project']+x} ]]; then - args['project']=$1 shift else @@ -4868,10 +4732,10 @@ orcli_export_csv_parse_requirements() { esac done - # :command.required_args_filter if [[ -z ${args['project']+x} ]]; then printf "missing required argument: PROJECT\nusage: orcli export csv PROJECT [OPTIONS]\n" >&2 + exit 1 fi @@ -4893,7 +4757,8 @@ orcli_export_csv_parse_requirements() { orcli_export_tsv_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_export_tsv_usage @@ -4919,7 +4784,6 @@ orcli_export_tsv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--select']="$2" shift shift @@ -4934,7 +4798,6 @@ orcli_export_tsv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--mode']="$2" shift shift @@ -4949,7 +4812,6 @@ orcli_export_tsv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--facets']="$2" shift shift @@ -4964,7 +4826,6 @@ orcli_export_tsv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--output']="$2" shift shift @@ -4979,7 +4840,6 @@ orcli_export_tsv_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--encoding']="$2" shift shift @@ -5005,8 +4865,8 @@ orcli_export_tsv_parse_requirements() { *) # :command.parse_requirements_case # :command.parse_requirements_case_simple + # :argument.case if [[ -z ${args['project']+x} ]]; then - args['project']=$1 shift else @@ -5018,10 +4878,10 @@ orcli_export_tsv_parse_requirements() { esac done - # :command.required_args_filter if [[ -z ${args['project']+x} ]]; then printf "missing required argument: PROJECT\nusage: orcli export tsv PROJECT [OPTIONS]\n" >&2 + exit 1 fi @@ -5042,7 +4902,8 @@ orcli_export_tsv_parse_requirements() { orcli_export_template_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_export_template_usage @@ -5068,7 +4929,6 @@ orcli_export_template_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--separator']="$2" shift shift @@ -5083,7 +4943,6 @@ orcli_export_template_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--prefix']="$2" shift shift @@ -5098,7 +4957,6 @@ orcli_export_template_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--suffix']="$2" shift shift @@ -5113,7 +4971,6 @@ orcli_export_template_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--mode']="$2" shift shift @@ -5128,7 +4985,6 @@ orcli_export_template_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--facets']="$2" shift shift @@ -5143,7 +4999,6 @@ orcli_export_template_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--output']="$2" shift shift @@ -5158,7 +5013,6 @@ orcli_export_template_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--encoding']="$2" shift shift @@ -5184,12 +5038,12 @@ orcli_export_template_parse_requirements() { *) # :command.parse_requirements_case # :command.parse_requirements_case_simple + # :argument.case if [[ -z ${args['project']+x} ]]; then - args['project']=$1 shift + # :argument.case elif [[ -z ${args['file']+x} ]]; then - args['file']=$1 shift else @@ -5201,10 +5055,10 @@ orcli_export_template_parse_requirements() { esac done - # :command.required_args_filter if [[ -z ${args['project']+x} ]]; then printf "missing required argument: PROJECT\nusage: orcli export template PROJECT [FILE] [OPTIONS]\n" >&2 + exit 1 fi @@ -5226,7 +5080,8 @@ orcli_export_template_parse_requirements() { orcli_run_parse_requirements() { # :command.fixed_flags_filter while [[ $# -gt 0 ]]; do - case "${1:-}" in + key="$1" + case "$key" in --help | -h) long_usage=yes orcli_run_usage @@ -5252,7 +5107,6 @@ orcli_run_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--memory']="$2" shift shift @@ -5267,7 +5121,6 @@ orcli_run_parse_requirements() { # :flag.case_arg if [[ -n ${2+x} ]]; then - args['--port']="$2" shift shift @@ -5301,14 +5154,15 @@ orcli_run_parse_requirements() { *) # :command.parse_requirements_case # :command.parse_requirements_case_repeatable - + # :argument.case_repeatable + escaped="$(printf '%q' "$1")" if [[ -z ${args['file']+x} ]]; then - args['file']="\"$1\"" - shift + args['file']="$escaped" else - args['file']="${args[file]} \"$1\"" - shift + args['file']="${args['file']} $escaped" + fi + shift ;; @@ -5337,10 +5191,11 @@ initialize() { # :command.run run() { - declare -A args=() - declare -A deps=() - declare -a other_args=() - declare -a input=() + declare -g -A args=() + declare -g -A deps=() + declare -g -a other_args=() + declare -g -a env_var_names=() + declare -g -a input=() normalize_input "$@" parse_requirements "${input[@]}" diff --git a/src/export_jsonl_command.sh b/src/export_jsonl_command.sh index 3d54ed1..307d562 100644 --- a/src/export_jsonl_command.sh +++ b/src/export_jsonl_command.sh @@ -11,7 +11,7 @@ if [[ ${args[--separator]} || ${args[--mode]} == "records" ]]; then if [[ ${args[--mode]} == "records" ]]; then engine='{"facets":[{"type":"list","columnName":"","expression":"grel:filter(row.columnNames,cn,row.record.cells[cn].value.length()>1)","selection":[]}],"mode":"row-based"}' fi - readarray -t columns_mv < <(curl -fs --data project="$projectid" --data "engine=${engine}" "${OPENREFINE_URL}/command/core/compute-facets" | jq -r '.facets[].choices[].v.v') + readarray -t columns_mv < <(curl -fs --data project="$projectid" --data "engine=${engine}" "${OPENREFINE_URL}/command/core/compute-facets$(get_csrf)" | jq -r '.facets[].choices[].v.v') readarray -t columns < <(curl -fs --get --data project="$projectid" "${OPENREFINE_URL}/command/core/get-columns-info" | jq -r '.[].name') readarray -t columns_mix < <(for i in "${columns[@]}"; do skip= diff --git a/src/lib/post_export.sh b/src/lib/post_export.sh index c150734..817e1dd 100644 --- a/src/lib/post_export.sh +++ b/src/lib/post_export.sh @@ -22,7 +22,7 @@ function post_export() { curloptions+=("--output" "${args[--output]}") fi # post - if ! curl -fs "${curloptions[@]}" "${OPENREFINE_URL}/command/core/export-rows"; then + if ! curl -fs "${curloptions[@]}" "${OPENREFINE_URL}/command/core/export-rows$(get_csrf)"; then error "exporting ${args[project]} failed!" else if [[ ${args[--output]} ]]; then diff --git a/src/lib/send_completions.sh b/src/lib/send_completions.sh index 3299b99..db7c108 100644 --- a/src/lib/send_completions.sh +++ b/src/lib/send_completions.sh @@ -13,7 +13,7 @@ send_completions() { echo $'' echo $' if [[ "${cur:0:1}" == "-" ]]; then' echo $' echo "$words"' - echo $' ' + echo $'' echo $' else' echo $' for word in $words; do' echo $' [[ "${word:0:1}" != "-" ]] && result+=("$word")' @@ -31,108 +31,108 @@ send_completions() { echo $'' echo $' case "$compline" in' echo $' \'export template\'*\'--mode\')' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur")' echo $' ;;' echo $'' echo $' \'export jsonl\'*\'--mode\')' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'export csv\'*\'--mode\')' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur")' echo $' ;;' echo $'' echo $' \'export tsv\'*\'--mode\')' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'export csv\'*\'--mode\')' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "rows records")" -- "$cur")' echo $' ;;' echo $'' echo $' \'export template\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --prefix --quiet --separator --suffix -h -q")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'import jsonl\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--guessCellValueTypes --help --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --rename --storeEmptyStrings --trimStrings -h -q")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'sort columns\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--first --help -h")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --prefix --quiet --separator --suffix -h -q")" -- "$cur")' echo $' ;;' echo $'' echo $' \'export jsonl\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet --separator -h -q")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet --separator -h -q")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'sort columns\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--first --help -h")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'import jsonl\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--guessCellValueTypes --help --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --rename --storeEmptyStrings --trimStrings -h -q")" -- "$cur")' echo $' ;;' echo $'' echo $' \'completions\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur")' echo $' ;;' echo $'' echo $' \'import json\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--guessCellValueTypes --help --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --recordPath --rename --storeEmptyStrings --trimStrings -h -q")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'import csv\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--blankCellsAsStrings --columnNames --encoding --guessCellValueTypes --headerLines --help --ignoreLines --ignoreQuoteCharacter --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --quoteCharacter --separator --skipBlankRows --skipDataLines --trimStrings -h -q")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'import tsv\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--blankCellsAsStrings --columnNames --encoding --guessCellValueTypes --headerLines --help --ignoreLines --ignoreQuoteCharacter --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --quoteCharacter --skipBlankRows --skipDataLines --trimStrings -h -q")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'export csv\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet --select --separator -h -q")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--guessCellValueTypes --help --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --recordPath --rename --storeEmptyStrings --trimStrings -h -q")" -- "$cur")' echo $' ;;' echo $'' echo $' \'export tsv\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet --select -h -q")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet --select -h -q")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'export csv\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet --select --separator -h -q")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'import csv\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--blankCellsAsStrings --columnNames --encoding --guessCellValueTypes --headerLines --help --ignoreLines --ignoreQuoteCharacter --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --quoteCharacter --separator --skipBlankRows --skipDataLines --trimStrings -h -q")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'import tsv\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--blankCellsAsStrings --columnNames --encoding --guessCellValueTypes --headerLines --help --ignoreLines --ignoreQuoteCharacter --includeArchiveFileName --includeFileSources --limit --projectName --projectTags --quiet --quoteCharacter --skipBlankRows --skipDataLines --trimStrings -h -q")" -- "$cur")' echo $' ;;' echo $'' echo $' \'transform\'*)' - 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 "--help --quiet -h -q")" -- "$cur")' echo $' ;;' echo $'' echo $' \'delete\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--force --help --quiet -f -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 $' \'import\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h csv json jsonl tsv")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'search\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --index -h")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help -h csv json jsonl tsv")" -- "$cur")' echo $' ;;' echo $'' echo $' \'export\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h csv jsonl template tsv")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help -h csv jsonl template tsv")" -- "$cur")' echo $' ;;' echo $'' - echo $' \'list\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'info\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur" )' - echo $' ;;' - echo $'' - echo $' \'sort\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h columns")" -- "$cur" )' + echo $' \'search\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help --index -h")" -- "$cur")' echo $' ;;' echo $'' echo $' \'test\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'sort\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help -h columns")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'info\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur")' + echo $' ;;' + echo $'' + echo $' \'list\'*)' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur")' echo $' ;;' echo $'' echo $' \'run\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --interactive --memory --port --quiet -h -q")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help --interactive --memory --port --quiet -h -q")" -- "$cur")' echo $' ;;' echo $'' echo $' *)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --version -h -v completions delete export import info list run search sort test transform")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_orcli_completions_filter "--help --version -h -v completions delete export import info list run search sort test transform")" -- "$cur")' echo $' ;;' echo $'' echo $' esac' echo $'} &&' - echo $'complete -F _orcli_completions orcli' + echo $' complete -F _orcli_completions orcli' echo $'' echo $'# ex: filetype=sh' } \ No newline at end of file