Merge pull request #79 from opencultureconsulting:felixlohmeier/bash-completion-59

add quiet flag
This commit is contained in:
Felix Lohmeier 2022-11-14 23:47:23 +01:00 committed by GitHub
commit 4086797909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 90 additions and 34 deletions

89
orcli
View File

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

View File

@ -27,11 +27,6 @@ examples:
orcli export tsv "duplicates"
EOF
flags:
- long: --quiet
short: -q
help: suppress log output, print errors only
commands:
- name: completions
help: |-
@ -62,6 +57,9 @@ commands:
- long: --projectName
arg: projectName
help: set a name for the OpenRefine project
- long: --quiet
short: -q
help: suppress log output, print errors only
examples:
- orcli import csv "file"
- 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.
default: "-"
repeatable: true
flags:
- long: --quiet
short: -q
help: suppress log output, print errors only
examples:
- orcli transform "duplicates" "history.json"
- cat "history.json" | orcli transform "duplicates"
@ -121,6 +123,9 @@ commands:
help: set character encoding
arg: encoding
default: "UTF-8"
- long: --quiet
short: -q
help: suppress log output, print errors only
examples:
- orcli export tsv "duplicates"
- orcli export tsv "duplicates" --output "duplicates.tsv"
@ -143,6 +148,9 @@ commands:
default: "3333"
- long: --interactive
help: do not exit on error and keep bash shell open
- long: --quiet
short: -q
help: suppress log output, print errors only
examples:
- orcli run --interactive
- |-

View File

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

View File

@ -35,15 +35,15 @@ send_completions() {
echo $' ;;'
echo $''
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 $' \'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 $' \'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 $' \'import\'*)'
@ -63,11 +63,11 @@ send_completions() {
echo $' ;;'
echo $''
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 $' 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 $' esac'

View File

@ -14,6 +14,11 @@ if ! [[ ${args[--interactive]} ]]; then
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
OPENREFINE_URL="http://localhost:${args[--port]}"