docopts API changes proposal
following #5
I had a look on the API proposed in the branch develop (See man ./docopts.1). Which is quite different from the current docopts API.
Old API (current)
eval "$(python3 $libexec/docopts -A args -V "$version" -h "$help" : "$@")" if ${args[--do-something]} ; then run_some_code fi
current API in branch develop, generating temporary files for each option on the filesystem
tmpdir=$(echo "$help" | python3 $libexec/docopts "$@") if [ -e $tmpdir/--do-something ]; then echo "Option given with argument $(cat $tmpdir/--do-something)." fi
I think about a new API, more like the python's library could be quite nice to have.
Something like the following code snippet, (to be completed…)
Specifying the associative array for $args and some shell centric behavior have to be considered, too.
#!/bin/bash # sourcing the API providing some bash functions ie: docopt() # still using the python parser source docopts.sh parsed=$(docopt -A args "$help_string" "$@" "$version" "$options_first") eval "$parsed"
and may be some shell helpers too:
help_string=$(get_help_string $0) array_opt=( $(get_docopt array "${args[--multiple-time]})" )
Please comment and suggest. I will develop and propose some versions.
You may also be tempted to say: "bash is not capable to handle simply the complexity of the JSON parsed structure behind docopt. Consider rewriting your shell script directly in python…"