hledger/shell-completion/parse-options.sh
Vladimir Zhelezov 5c2dd6fa2f Move back commands/options parsing to separate shell scripts
It made the Makefile more difficult to read and this way we can
take advantage of `set -e`, `-o pipefail` and friends.

Clean up debugging targets
2021-02-28 08:33:18 +01:00

15 lines
477 B
Bash
Executable File

#!/usr/bin/env bash
# Parse hledger's help and output long options. Do not propose single letter
# completions. Options requiring an argument make that explicit by appending the
# equal sign (=)
set -euo pipefail
declare subcommand=${1:-}
declare hledgerArgs=(--help)
[[ -n $subcommand ]] && hledgerArgs=("$subcommand" "${hledgerArgs[@]}")
hledger "${hledgerArgs[@]}" |
sed -rn '/^\s+-/p' |
sed -rn 's/^\s{1,4}(-.)?\s{1,4}(--[a-zA-Z][-_a-zA-Z0-9]+=?).*/\2/p' |
sort -u