Skip to content

Commit

Permalink
Issue #95: Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
dakusui committed Dec 10, 2019
1 parent 7086e48 commit 04bfe30
Show file tree
Hide file tree
Showing 8 changed files with 803 additions and 23 deletions.
9 changes: 5 additions & 4 deletions docs/manual.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

[source,bash]
----
jq-front [-h|--help] [-e|--enable-templating] [-d|--disable-templating] [--validation=no|strict|lenient] [TARGET]
jq-front [-h|--help] [--validation=no|strict|lenient] [--nested-templating-levels=num] [TARGET]
----

- `-h`, `--help`: Shows a help
- `-e`, `--enable-templating`: Enables templating (default)
- `-d`, `--disable-templating`: Disables templating
- `-h`, `--help`: Shows this help
- `--validation`: Validation mode.
`no`, `strict`, and `lenient` are available.
The default is `no`.
- `--nested-templating-levels`: Number of times templating happens by default.
The default is `5`.
If templating doesn't finish within `num` times, an error will be reported.
- `TARGET`: A file to be processed.

=== Environment variables
Expand Down
18 changes: 6 additions & 12 deletions jq-front
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,16 @@ function _sourced_files_dir() {
}

function usage() {
message "Usage: $0 [-h|--help] [-e|--enable-templating] [-e|--enable-templating] [--validation=[no|lenient|strict]] TARGET"
message "Usage: $0 [-h|--help] [--validation=[no|lenient|strict]] [nested-templating-levels] TARGET"
}

function main() {
# Call getopt to validate the provided input.
options=$(getopt \
-o hde \
--long help,disable-templating,enable-templating,validation:,nested-templating-levels: -- "$@") || {
usage_exit
-o he \
--long help,validation:,nested-templating-levels: -- "$@") || {
usage
abort "Failed to parse command line:'$*'"
}
if [[ $# -gt 0 ]]; then
eval set -- "$options"
Expand All @@ -75,16 +76,9 @@ function main() {
usage
exit 0
;;
-d | --disable-templating)
_JF_TEMPLATING_ENABLED=no
shift
;;
-e | --enable-templating)
_JF_TEMPLATING_ENABLED=yes
shift
;;
--nested-templating-levels)
_JF_NESTED_TEMPLATING_LEVELS=$2
[[ "$2" != 0 ]] || _JF_TEMPLATING_ENABLED=no
shift
shift
;;
Expand Down
5 changes: 3 additions & 2 deletions lib/templating.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ function _perform_templating() {
if [[ "${_c}" -eq 0 ]]; then
error "Templating has been repeated ${_levels} time(s) but it did not finish.: Keys left untemplated are: [${_keys[*]}]"
fi
debug "begin loop"
debug "begin inner loop: (1)"
for i in "${_keys[@]}"; do
local _node_value _templated_node_value _ret_file
debug "processing: ${i}"
_node_value="$(value_at "${i}" "${_ret}")"
_ret_file=$(mktemp_with_content "${_ret}")
_templated_node_value="$(_render_text_node "${_node_value}" "${i}" "${_ret_file}")"
_ret="$(jq -r -c -n "input|${i}=input" <(echo "${_ret}") <(echo "${_templated_node_value}"))"
done
_c=$((_c - 1))
debug "end loop"
debug "end inner loop: (1)"
done
echo "${_ret}"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/help/expected.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Usage:
jq-front [-h|--help] [-e|--enable-templating] [-e|--enable-templating] [--validation=[no|lenient|strict]] TARGET
[-h|--help] [--validation=[no|lenient|strict]] [nested-templating-levels] TARGET
Loading

0 comments on commit 04bfe30

Please sign in to comment.