Skip to content

Commit

Permalink
Remove opt-choice. Other fixes. (#27)
Browse files Browse the repository at this point in the history
This PR removes `opt-choice`, because (a) all client code has migrated
off of it, and (b) its functionality is well-covered by the more general
`opt-alias`.

In addition:

* Added a handful of missing test cases.
* Fixed a couple of problems with the general JSON-postprocessing
facilities.
  • Loading branch information
danfuzz authored Oct 24, 2023
2 parents 6d22293 + bfd4022 commit 493444a
Show file tree
Hide file tree
Showing 55 changed files with 126 additions and 519 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Breaking changes:
* New recommended processing call `process-args "$@" || exit "$?"`, because
of "magic" reduction noted below.
* Renamed `--init` to `--default`, which is a better word for the meaning.
* Removed `opt-choice`, as it's now covered by the more general `opt-alias`.
* `define-usage`: Dropped "magical" `exit` behavior.

Other notable changes:
Expand All @@ -24,8 +25,9 @@ Other notable changes:
* Added `opt-alias` to allow for expansion of single no-value options into
multiple options (including with values). Used underlying facility to
rework implementation of single-character short options.
* Added multi-value option syntax `--opt-name[]=...`, along with helper
function `values` for use sites.
* Added `opt-multi` to accept multi-valued options. Relatedly, added
multi-value option passing syntax `--opt-name[]=...`, along with helper
function `vals` for use sites.
* `define-usage`: New option `--with-help` to help reduce boilerplate.
* `stderr-msg`: New option `--file-line`.
* Added a lot of tests, covering almost all of the core library functionality.
Expand Down
31 changes: 7 additions & 24 deletions scripts/lib/bashy-basics/_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function json-postproc-output {
: # Nothing to do.
;;
lines|raw|raw0)
jget "${outputArray}" --output="${_bashy_jsonOutputStyle}" '.[]'
jget --output="${_bashy_jsonOutputStyle}" "${outputArray}" '.[]'
;;
'')
error-msg 'No JSON --output option supplied (or implied).'
Expand All @@ -235,33 +235,16 @@ function json-postproc-strings {
local output=("$@")

case "${_bashy_jsonOutputStyle}" in
array)
# Form a JSON array, and tell the postprocessor about it.
jarray --input=strings -- "${output[@]}" \
| jpostproc "${_bashy_jsonPostArgs[@]}"
;;
json)
# Form a sequence of JSON strings, and tell the postprocessor about
# it.
jstring -- "${output[@]}" \
| jpostproc "${_bashy_jsonPostArgs[@]}"
;;
none)
: # Nothing to do.
;;
lines|raw|raw0)
# Form a sequence of JSON strings, and then ask `jval` to use its
# output processing on it.
jstring -- "${output[@]}" \
| jval --input=read --output="${_bashy_jsonOutputStyle}"
;;
'')
error-msg 'No JSON --output option supplied (or implied).'
return 1
;;
*)
error-msg "Unrecognized JSON --output option: ${_bashy_jsonOutputStyle}"
return 1
# Form a JSON array, and tell the postprocessor about it.
local outputArray
outputArray="$(jarray --input=strings -- "${output[@]}")" \
|| return "$?"

json-postproc-output "${outputArray}"
;;
esac
}
Expand Down
44 changes: 0 additions & 44 deletions scripts/lib/bashy-core/arg-processor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,50 +138,6 @@ function opt-alias {
"${args[@]}"
}

# Declares a "choice" option set, consisting of one or more options. On a
# commandline, no choice option accepts a value (because the option name itself
# implies the value). If left unspecified, the initial variable value for a
# choice option is `''` (the empty string). This definer also accepts the
# `--required` option.
function opt-choice {
local optCall=''
local optDefault=''
local optRequired=0
local optVar=''
local args=("$@")
_argproc_janky-args --multi-arg call default required var \
|| return 1

if [[ ${optVar} != '' ]]; then
# Set up the variable initializer.
_argproc_initStatements+=("${optVar}=$(_argproc_quote "${optDefault}")")
fi

local allNames=()
local spec
for spec in "${args[@]}"; do
local specName=''
local specHasValue=0
local specShort=''
local specValue=''
_argproc_parse-spec --short --value "${spec}" \
|| return 1

if (( !specHasValue )); then
specValue="${specName}"
fi

_argproc_define-no-value-arg --option \
"${specName}" "${specValue}" "${optCall}" "${optVar}" "${specShort}"

allNames+=("${specName}")
done

if (( optRequired )); then
_argproc_add-required-arg-postcheck "${allNames[@]}"
fi
}

# Declares a "multi-value" option, which allows passing zero or more values. No
# `<short>` or `<value>` is allowed in the argument spec. These options are
# accepted via the syntax `--<name>[]=<values>` where <values> is a
Expand Down
File renamed without changes.
150 changes: 0 additions & 150 deletions tests/02-core/02-arg-processor/09-reqchoice/expect.md

This file was deleted.

1 change: 0 additions & 1 deletion tests/02-core/02-arg-processor/09-reqchoice/info.md

This file was deleted.

46 changes: 0 additions & 46 deletions tests/02-core/02-arg-processor/09-reqchoice/run

This file was deleted.

22 changes: 0 additions & 22 deletions tests/02-core/02-arg-processor/09-reqchoice/the-cmd

This file was deleted.

Loading

0 comments on commit 493444a

Please sign in to comment.