reuse args and flags

This commit is contained in:
felixlohmeier 2022-12-13 21:20:36 +00:00
parent cefefde3fd
commit fbf9b04188
3 changed files with 39 additions and 60 deletions

View File

@ -10,7 +10,7 @@ Bash script to control OpenRefine via [its HTTP API](https://docs.openrefine.org
* allows execution of arbitrary bash scripts * allows execution of arbitrary bash scripts
* interactive mode for playing around and debugging * interactive mode for playing around and debugging
* your existing OpenRefine data will not be touched * your existing OpenRefine data will not be touched
* import CSV, ~~TSV, line-based TXT, fixed-width TXT, JSON or XML~~ (and specify input options) * import CSV, TSV, ~~line-based TXT, fixed-width TXT, JSON or XML~~ (and specify input options)
* supports stdin, multiple files and URLs * supports stdin, multiple files and URLs
* transform data by providing an [undo/redo](https://docs.openrefine.org/manual/running#history-undoredo) JSON file * transform data by providing an [undo/redo](https://docs.openrefine.org/manual/running#history-undoredo) JSON file
* orcli calls specific endpoints for each operation to provide improved error handling and logging * orcli calls specific endpoints for each operation to provide improved error handling and logging

8
orcli
View File

@ -271,7 +271,7 @@ orcli_import_csv_usage() {
printf "Examples:\n" printf "Examples:\n"
printf " orcli import csv \"file\"\n" printf " orcli import csv \"file\"\n"
printf " orcli import csv \"file1\" \"file2\"\n" printf " orcli import csv \"file1\" \"file2\"\n"
printf " cat \"file\" | orcli import csv\n" printf " head -n 100 \"file\" | orcli import csv\n"
printf " orcli import csv \"https://git.io/fj5hF\"\n" printf " orcli import csv \"https://git.io/fj5hF\"\n"
printf " orcli import csv \"file\" \\\\\n --separator \";\" \\\\\n --encoding \"ISO-8859-1\" \\\\\n --trimStrings \\\\\n --projectName \"duplicates\"\n" printf " orcli import csv \"file\" \\\\\n --separator \";\" \\\\\n --encoding \"ISO-8859-1\" \\\\\n --trimStrings \\\\\n --projectName \"duplicates\"\n"
echo echo
@ -339,7 +339,7 @@ orcli_import_tsv_usage() {
printf "Examples:\n" printf "Examples:\n"
printf " orcli import tsv \"file\"\n" printf " orcli import tsv \"file\"\n"
printf " orcli import tsv \"file1\" \"file2\"\n" printf " orcli import tsv \"file1\" \"file2\"\n"
printf " cat \"file\" | orcli import tsv\n" printf " head -n 100 \"file\" | orcli import tsv\n"
printf " orcli import tsv \"https://git.io/fj5hF\"\n" printf " orcli import tsv \"https://git.io/fj5hF\"\n"
printf " orcli import tsv \"file\" \\\\\n --separator \";\" \\\\\n --encoding \"ISO-8859-1\" \\\\\n --trimStrings \\\\\n --projectName \"duplicates\"\n" printf " orcli import tsv \"file\" \\\\\n --separator \";\" \\\\\n --encoding \"ISO-8859-1\" \\\\\n --trimStrings \\\\\n --projectName \"duplicates\"\n"
echo echo
@ -490,7 +490,7 @@ orcli_transform_usage() {
# :argument.usage # :argument.usage
echo " FILE..." echo " FILE..."
printf " Path to one or more files or URLs containing OpenRefine's undo/redo\n operation history in JSON format. When FILE is -, read standard input.\n" printf " Path to one or more files or URLs. When FILE is -, read standard input.\n"
printf " Default: -\n" printf " Default: -\n"
echo echo
@ -652,7 +652,7 @@ orcli_run_usage() {
# :argument.usage # :argument.usage
echo " FILE..." echo " FILE..."
printf " Path to one or more files. When FILE is -, read standard input.\n" printf " Path to one or more files or URLs. When FILE is -, read standard input.\n"
printf " Default: -\n" printf " Default: -\n"
echo echo

View File

@ -36,14 +36,16 @@ commands:
- name: delete - name: delete
help: delete OpenRefine project help: delete OpenRefine project
args: args:
- name: project - &project
name: project
help: project name or id help: project name or id
required: true required: true
flags: flags:
- long: --force - long: --force
short: -f short: -f
help: delete all projects with the same name help: delete all projects with the same name
- long: --quiet - &quiet
long: --quiet
short: -q short: -q
help: suppress log output, print errors only help: suppress log output, print errors only
examples: examples:
@ -57,30 +59,33 @@ commands:
- name: csv - name: csv
help: import character-separated values (CSV) help: import character-separated values (CSV)
args: args:
- name: file - &file
name: file
help: Path to one or more files or URLs. When FILE is -, read standard input. help: Path to one or more files or URLs. When FILE is -, read standard input.
default: "-" default: "-"
repeatable: true repeatable: true
flags: flags:
- long: --separator - &separator
long: --separator
help: character(s) that separates columns help: character(s) that separates columns
arg: separator arg: separator
default: "," default: ","
- long: --encoding - &encoding_import
long: --encoding
help: set character encoding help: set character encoding
arg: encoding arg: encoding
- long: --trimStrings - &trimStrings
long: --trimStrings
help: trim leading & trailing whitespace from strings help: trim leading & trailing whitespace from strings
- long: --projectName - &projectName
long: --projectName
arg: projectName arg: projectName
help: set a name for the OpenRefine project help: set a name for the OpenRefine project
- long: --quiet - *quiet
short: -q
help: suppress log output, print errors only
examples: examples:
- orcli import csv "file" - orcli import csv "file"
- orcli import csv "file1" "file2" - orcli import csv "file1" "file2"
- cat "file" | orcli import csv - head -n 100 "file" | orcli import csv
- orcli import csv "https://git.io/fj5hF" - orcli import csv "https://git.io/fj5hF"
- |- - |-
orcli import csv "file" \\\\ orcli import csv "file" \\\\
@ -92,26 +97,16 @@ commands:
- name: tsv - name: tsv
help: import tab-separated values (TSV) help: import tab-separated values (TSV)
args: args:
- name: file - *file
help: Path to one or more files or URLs. When FILE is -, read standard input.
default: "-"
repeatable: true
flags: flags:
- long: --encoding - *encoding_import
help: set character encoding - *trimStrings
arg: encoding - *projectName
- long: --trimStrings - *quiet
help: trim leading & trailing whitespace from strings
- long: --projectName
arg: projectName
help: set a name for the OpenRefine project
- long: --quiet
short: -q
help: suppress log output, print errors only
examples: examples:
- orcli import tsv "file" - orcli import tsv "file"
- orcli import tsv "file1" "file2" - orcli import tsv "file1" "file2"
- cat "file" | orcli import tsv - head -n 100 "file" | orcli import tsv
- orcli import tsv "https://git.io/fj5hF" - orcli import tsv "https://git.io/fj5hF"
- |- - |-
orcli import tsv "file" \\\\ orcli import tsv "file" \\\\
@ -126,9 +121,7 @@ commands:
- name: info - name: info
help: show OpenRefine project's metadata help: show OpenRefine project's metadata
args: args:
- name: project - *project
help: project name or id
required: true
examples: examples:
- orcli info "duplicates" - orcli info "duplicates"
- orcli info 1234567890123 - orcli info 1234567890123
@ -139,17 +132,10 @@ commands:
- name: transform - name: transform
help: apply undo/redo JSON file(s) to an OpenRefine project help: apply undo/redo JSON file(s) to an OpenRefine project
args: args:
- name: project - *project
help: project name or id - *file
required: true
- name: file
help: Path to one or more files or URLs containing OpenRefine's undo/redo operation history in JSON format. When FILE is -, read standard input.
default: "-"
repeatable: true
flags: flags:
- long: --quiet - *quiet
short: -q
help: suppress log output, print errors only
examples: examples:
- orcli transform "duplicates" "history.json" - orcli transform "duplicates" "history.json"
- cat "history.json" | orcli transform "duplicates" - cat "history.json" | orcli transform "duplicates"
@ -163,20 +149,18 @@ commands:
- name: tsv - name: tsv
help: export tab-separated values (TSV) help: export tab-separated values (TSV)
args: args:
- name: project - *project
help: project name or id
required: true
flags: flags:
- long: --output - &output
long: --output
help: Write to file instead of stdout help: Write to file instead of stdout
arg: file arg: file
- long: --encoding - &encoding_export
long: --encoding
help: set character encoding help: set character encoding
arg: encoding arg: encoding
default: "UTF-8" default: "UTF-8"
- long: --quiet - *quiet
short: -q
help: suppress log output, print errors only
examples: examples:
- orcli export tsv "duplicates" - orcli export tsv "duplicates"
- orcli export tsv "duplicates" --output "duplicates.tsv" - orcli export tsv "duplicates" --output "duplicates.tsv"
@ -184,10 +168,7 @@ commands:
- name: run - name: run
help: run tmp OpenRefine workspace and execute shell script(s) help: run tmp OpenRefine workspace and execute shell script(s)
args: args:
- name: file - *file
help: Path to one or more files. When FILE is -, read standard input.
default: "-"
repeatable: true
flags: flags:
- long: --memory - long: --memory
help: maximum RAM for OpenRefine java heap space help: maximum RAM for OpenRefine java heap space
@ -199,9 +180,7 @@ commands:
default: "3333" default: "3333"
- long: --interactive - long: --interactive
help: do not exit on error and keep bash shell open help: do not exit on error and keep bash shell open
- long: --quiet - *quiet
short: -q
help: suppress log output, print errors only
examples: examples:
- orcli run --interactive - orcli run --interactive
- |- - |-