add quiet flag

This commit is contained in:
felixlohmeier 2022-11-14 22:46:18 +00:00
parent c524058ca6
commit 1edc6f5672
5 changed files with 90 additions and 34 deletions

89
orcli
View File

@ -28,7 +28,7 @@ orcli_usage() {
fi fi
printf "Usage:\n" printf "Usage:\n"
printf " orcli [OPTIONS] COMMAND\n" printf " orcli COMMAND\n"
printf " orcli [COMMAND] --help | -h\n" printf " orcli [COMMAND] --help | -h\n"
printf " orcli --version | -v\n" printf " orcli --version | -v\n"
echo echo
@ -55,12 +55,6 @@ orcli_usage() {
printf " Show version number\n" printf " Show version number\n"
echo echo
# :command.usage_flags
# :flag.usage
echo " --quiet, -q"
printf " suppress log output, print errors only\n"
echo
# :command.usage_environment_variables # :command.usage_environment_variables
printf "Environment Variables:\n" printf "Environment Variables:\n"
@ -202,6 +196,11 @@ orcli_import_csv_usage() {
printf " set a name for the OpenRefine project\n" printf " set a name for the OpenRefine project\n"
echo echo
# :flag.usage
echo " --quiet, -q"
printf " suppress log output, print errors only\n"
echo
# :command.usage_args # :command.usage_args
printf "Arguments:\n" printf "Arguments:\n"
@ -308,7 +307,7 @@ orcli_transform_usage() {
fi fi
printf "Usage:\n" printf "Usage:\n"
printf " orcli transform PROJECT [FILE...]\n" printf " orcli transform PROJECT [FILE...] [OPTIONS]\n"
printf " orcli transform --help | -h\n" printf " orcli transform --help | -h\n"
echo echo
@ -321,6 +320,12 @@ orcli_transform_usage() {
printf " Show this help\n" printf " Show this help\n"
echo echo
# :command.usage_flags
# :flag.usage
echo " --quiet, -q"
printf " suppress log output, print errors only\n"
echo
# :command.usage_args # :command.usage_args
printf "Arguments:\n" printf "Arguments:\n"
@ -417,6 +422,11 @@ orcli_export_tsv_usage() {
printf " Default: UTF-8\n" printf " Default: UTF-8\n"
echo echo
# :flag.usage
echo " --quiet, -q"
printf " suppress log output, print errors only\n"
echo
# :command.usage_args # :command.usage_args
printf "Arguments:\n" printf "Arguments:\n"
@ -478,6 +488,11 @@ orcli_run_usage() {
printf " do not exit on error and keep bash shell open\n" printf " do not exit on error and keep bash shell open\n"
echo echo
# :flag.usage
echo " --quiet, -q"
printf " suppress log output, print errors only\n"
echo
# :command.usage_args # :command.usage_args
printf "Arguments:\n" printf "Arguments:\n"
@ -664,7 +679,7 @@ function error() {
exit 1 exit 1
} }
function log() { function log() {
if ! [[ ${args[--quiet]} ]]; then if ! [[ ${args[--quiet]} || $ORCLI_QUIET ]]; then
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')] $1" echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')] $1"
shift shift
for msg in "$@"; do echo >&2 " $msg"; done for msg in "$@"; do echo >&2 " $msg"; done
@ -739,15 +754,15 @@ send_completions() {
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'import csv\'*)' echo $' \'import csv\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --help --projectName --separator --trimStrings -h")" -- "$cur" )' echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --help --projectName --quiet --separator --trimStrings -h -q")" -- "$cur" )'
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'export tsv\'*)' echo $' \'export tsv\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --help --output -h")" -- "$cur" )' echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --help --output --quiet -h -q")" -- "$cur" )'
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'transform\'*)' echo $' \'transform\'*)'
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 --quiet -h -q")" -- "$cur" )'
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'import\'*)' echo $' \'import\'*)'
@ -767,11 +782,11 @@ send_completions() {
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'run\'*)' echo $' \'run\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --interactive --memory --port -h")" -- "$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 $''
echo $' *)' echo $' *)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --quiet --version -h -q -v completions export import info list run transform")" -- "$cur" )' echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --version -h -v completions export import info list run transform")" -- "$cur" )'
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' esac' echo $' esac'
@ -1004,6 +1019,11 @@ orcli_run_command() {
fi fi
fi fi
# assume that quiet flag shall suppress log output generally in batch mode
if [[ ${args[--quiet]} ]]; then
export ORCLI_QUIET=1
fi
# update OPENREFINE_URL env # update OPENREFINE_URL env
OPENREFINE_URL="http://localhost:${args[--port]}" OPENREFINE_URL="http://localhost:${args[--port]}"
@ -1099,14 +1119,6 @@ parse_requirements() {
exit exit
;; ;;
# :flag.case
--quiet | -q )
# :flag.case_no_arg
args[--quiet]=1
shift
;;
esac esac
# :command.environment_variables_filter # :command.environment_variables_filter
@ -1387,6 +1399,14 @@ orcli_import_csv_parse_requirements() {
fi fi
;; ;;
# :flag.case
--quiet | -q )
# :flag.case_no_arg
args[--quiet]=1
shift
;;
-?* ) -?* )
printf "invalid option: %s\n" "$key" >&2 printf "invalid option: %s\n" "$key" >&2
exit 1 exit 1
@ -1522,6 +1542,13 @@ orcli_transform_parse_requirements() {
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
key="$1" key="$1"
case "$key" in case "$key" in
# :flag.case
--quiet | -q )
# :flag.case_no_arg
args[--quiet]=1
shift
;;
-?* ) -?* )
printf "invalid option: %s\n" "$key" >&2 printf "invalid option: %s\n" "$key" >&2
@ -1551,7 +1578,7 @@ orcli_transform_parse_requirements() {
# :command.required_args_filter # :command.required_args_filter
if [[ -z ${args[project]+x} ]]; then if [[ -z ${args[project]+x} ]]; then
printf "missing required argument: PROJECT\nusage: orcli transform PROJECT [FILE...]\n" >&2 printf "missing required argument: PROJECT\nusage: orcli transform PROJECT [FILE...] [OPTIONS]\n" >&2
exit 1 exit 1
fi fi
@ -1671,6 +1698,14 @@ orcli_export_tsv_parse_requirements() {
fi fi
;; ;;
# :flag.case
--quiet | -q )
# :flag.case_no_arg
args[--quiet]=1
shift
;;
-?* ) -?* )
printf "invalid option: %s\n" "$key" >&2 printf "invalid option: %s\n" "$key" >&2
exit 1 exit 1
@ -1761,6 +1796,14 @@ orcli_run_parse_requirements() {
shift shift
;; ;;
# :flag.case
--quiet | -q )
# :flag.case_no_arg
args[--quiet]=1
shift
;;
-?* ) -?* )
printf "invalid option: %s\n" "$key" >&2 printf "invalid option: %s\n" "$key" >&2
exit 1 exit 1

View File

@ -27,11 +27,6 @@ examples:
orcli export tsv "duplicates" orcli export tsv "duplicates"
EOF EOF
flags:
- long: --quiet
short: -q
help: suppress log output, print errors only
commands: commands:
- name: completions - name: completions
help: |- help: |-
@ -62,6 +57,9 @@ commands:
- long: --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
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"
@ -97,6 +95,10 @@ commands:
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. 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: "-" default: "-"
repeatable: true repeatable: true
flags:
- long: --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"
@ -121,6 +123,9 @@ commands:
help: set character encoding help: set character encoding
arg: encoding arg: encoding
default: "UTF-8" default: "UTF-8"
- long: --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"
@ -143,6 +148,9 @@ 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
short: -q
help: suppress log output, print errors only
examples: examples:
- orcli run --interactive - orcli run --interactive
- |- - |-

View File

@ -7,7 +7,7 @@ function error() {
exit 1 exit 1
} }
function log() { function log() {
if ! [[ ${args[--quiet]} ]]; then if ! [[ ${args[--quiet]} || $ORCLI_QUIET ]]; then
echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')] $1" echo >&2 "[$(date +'%Y-%m-%dT%H:%M:%S')] $1"
shift shift
for msg in "$@"; do echo >&2 " $msg"; done for msg in "$@"; do echo >&2 " $msg"; done

View File

@ -35,15 +35,15 @@ send_completions() {
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'import csv\'*)' echo $' \'import csv\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --help --projectName --separator --trimStrings -h")" -- "$cur" )' echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --help --projectName --quiet --separator --trimStrings -h -q")" -- "$cur" )'
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'export tsv\'*)' echo $' \'export tsv\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --help --output -h")" -- "$cur" )' echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --help --output --quiet -h -q")" -- "$cur" )'
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'transform\'*)' echo $' \'transform\'*)'
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 --quiet -h -q")" -- "$cur" )'
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'import\'*)' echo $' \'import\'*)'
@ -63,11 +63,11 @@ send_completions() {
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'run\'*)' echo $' \'run\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --interactive --memory --port -h")" -- "$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 $''
echo $' *)' echo $' *)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --quiet --version -h -q -v completions export import info list run transform")" -- "$cur" )' echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --version -h -v completions export import info list run transform")" -- "$cur" )'
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' esac' echo $' esac'

View File

@ -14,6 +14,11 @@ if ! [[ ${args[--interactive]} ]]; then
fi fi
fi fi
# assume that quiet flag shall suppress log output generally in batch mode
if [[ ${args[--quiet]} ]]; then
export ORCLI_QUIET=1
fi
# update OPENREFINE_URL env # update OPENREFINE_URL env
OPENREFINE_URL="http://localhost:${args[--port]}" OPENREFINE_URL="http://localhost:${args[--port]}"