Skip to content

Commit

Permalink
builtin: print usages of emulated builtins on option errors
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Dec 11, 2021
1 parent e1ad2f1 commit 6f74021
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog.md
Expand Up @@ -244,6 +244,7 @@
- decode: work around the overwritten builtin `set` (reported by eadmaster) `#D1680` a6b4e2c
- complete: work around the variable leaks by `virsh` completion from `libvirt` (reported by telometto) `#D1682` f985b9a
- stty: do not remove keydefs for <kbd>C-u</kbd>, <kbd>C-v</kbd>, <kbd>C-w</kbd>, and <kbd>C-?</kbd> (reported by laoshaw) `#D1683` 82f74f0
- builtin: print usages of emulated builtins on option errors `#D1694` 0000000

## Internal changes and fixes

Expand Down
12 changes: 12 additions & 0 deletions note.txt
Expand Up @@ -5517,6 +5517,18 @@ bash_tips

2021-12-08

* complete: bind -[TAB] で bash-completion がオプションを生成してくれない [#D1694]
ble.sh の外側ではちゃんと生成してくれている。

これは分かった。上書きしている builtin が --usage オプションに対応していな
いのが原因。というか unrecognized option と表示する時に、エラーメッセージと
して usage を出力していて、それに従って usage が出力されているのであった。

うーん。これに対してはどの様に対処するべきだろうか。つまり、bash-completion
は敢えて誤った用法でコマンドを呼び出してその結果を解析している。上書きする
builtin は誤った用法に対するエラー時の振る舞いに対しても同様に振る舞う必要
があるのだろうか?

* mandb: --help から読み出し? [#D1693]
https://github.com/akinomyoga/ble.sh/issues/158

Expand Down
2 changes: 2 additions & 0 deletions src/decode.sh
Expand Up @@ -3949,6 +3949,8 @@ function ble/builtin/bind {
if [[ $_ble_decode_bind_state == none ]]; then
builtin bind "$@"; ext=$?
elif [[ $flags == *[eh]* ]]; then
[[ $flags == *e* ]] &&
builtin bind --usage 2>&1 1>/dev/null | ble/bin/grep ^bind >&2
ext=2
fi

Expand Down
5 changes: 4 additions & 1 deletion src/edit.sh
Expand Up @@ -8255,8 +8255,11 @@ function ble/builtin/read/.impl {

ble/builtin/read/.read-arguments "$@"
if [[ $opt_flags == *[HE]* ]]; then
[[ $opt_flags == *H* ]] &&
if [[ $opt_flags == *H* ]]; then
builtin read --help
elif [[ $opt_flags == *E* ]]; then
builtin read --usage 2>&1 1>/dev/null | ble/bin/grep ^read >&2
fi
return 2
fi

Expand Down
5 changes: 4 additions & 1 deletion src/history.sh
Expand Up @@ -1470,7 +1470,10 @@ function ble/builtin/history {
esac
done
done
[[ $flag_error ]] && return 2
if [[ $flag_error ]]; then
builtin history --usage 2>&1 1>/dev/null | ble/bin/grep ^history >&2
return 2
fi

if [[ $flags == *h* ]]; then
builtin history --help
Expand Down
1 change: 1 addition & 0 deletions src/util.sh
Expand Up @@ -1892,6 +1892,7 @@ function ble/builtin/trap {
builtin trap --help
return 2
elif [[ $flags == *E* ]]; then
builtin trap --usage 2>&1 1>/dev/null | ble/bin/grep ^trap >&2
return 2
elif [[ $flags == *l* ]]; then
builtin trap -l
Expand Down

0 comments on commit 6f74021

Please sign in to comment.