Skip to content

Commit 8aaaf84

Browse files
authored
Merge pull request #5 from woblerr/sync_with_2_39
Sync with pgBackRest v2.39.
2 parents 0aef670 + 920f283 commit 8aaaf84

File tree

1 file changed

+53
-8
lines changed

1 file changed

+53
-8
lines changed

pgbackrest-completion.sh

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,24 @@ __pgbackrest_command_options_values() {
2727
echo ${command_options_values}
2828
}
2929

30-
# The '--output' option is available for 2 commands ('repo-ls' and 'info') with the same values.
30+
# The '--output' option is available for 'repo-ls' and 'info' commands with the same values.
3131
# For 'repo-ls' command displayed additional information in the same format.
32-
# To simplify the solution, the option values are specified directly.
33-
# If the values for different commands will be different, this code must be reviewed.
32+
# To simplify the solution and not write additional regexp, the option values are specified directly.
3433
__pgbackrest_command_options_values_output() {
3534
echo "text"$'\n'"json"
3635
}
3736

37+
# The '--output' option is available for 'verify' command with another values.
38+
# As well as other formatting of the hint text.
39+
# When new commands with unique options list appear, refactoring will be required.
40+
__pgbackrest_command_options_values_output_verify() {
41+
echo "none"$'\n'"text"
42+
}
43+
3844
# The '--buffer-size' displays values in the user friendly format starting from pgBackRest v2.37.
3945
# In earlier versions, values in bytes will be substituted.
4046
# https://github.com/pgbackrest/pgbackrest/pull/1557
41-
__pgbackrest_command_options_values_buffer_size(){
47+
__pgbackrest_command_options_values_buffer_size() {
4248
local buffer_size_option_values
4349
# Regex for valid values like:
4450
# 16384,
@@ -55,6 +61,12 @@ __pgbackrest_command_options_values_buffer_size(){
5561
echo ${buffer_size_option_values[@]}
5662
}
5763

64+
# The '--type' option for 'info' command has non-standard hint text formating for parsing.
65+
# If the number of commands with non-standard hint text formating will grow, refactoring will be required.
66+
__pgbackrest_command_options_values_type_info() {
67+
echo "full"$'\n'"incr"$'\n'"diff"
68+
}
69+
5870
# If no stanza - return empty string; nothing to complete.
5971
# May be some delays in getting stanza names.
6072
__pgbackrest_stanza_values() {
@@ -150,11 +162,29 @@ _pgbackrest() {
150162
COMPREPLY=($(compgen -W "$(__pgbackrest_stanza_values)" -- ${cur}))
151163
return 0;;
152164
--output)
153-
COMPREPLY=($(compgen -W "$(__pgbackrest_command_options_values_output)" -- ${cur}))
154-
return 0;;
165+
# Different values for the '--output' option depending on the command.
166+
case ${COMP_WORDS[1]} in
167+
verify)
168+
COMPREPLY=($(compgen -W "$(__pgbackrest_command_options_values_output_verify)" -- ${cur}))
169+
return 0;;
170+
*)
171+
COMPREPLY=($(compgen -W "$(__pgbackrest_command_options_values_output)" -- ${cur}))
172+
return 0;;
173+
esac;;
155174
--buffer-size)
156175
COMPREPLY=($(compgen -W "$(__pgbackrest_command_options_values_buffer_size)" -- ${cur}))
157176
return 0;;
177+
--type)
178+
# Different values for the '--type' option depending on the command.
179+
case ${COMP_WORDS[1]} in
180+
info)
181+
COMPREPLY=($(compgen -W "$(__pgbackrest_command_options_values_backup_types)" -- ${cur}))
182+
return 0;;
183+
*)
184+
# The usual completion for all other commands.
185+
COMPREPLY=($(compgen -W "$(__pgbackrest_command_options_values)" -- ${cur}))
186+
return 0;;
187+
esac;;
158188
*)
159189
if [[ ${prev} =~ ${arg_regex} ]]; then
160190
COMPREPLY=($(compgen -W "$(__pgbackrest_command_options_values)" -- ${cur}))
@@ -186,11 +216,26 @@ _pgbackrest() {
186216
COMPREPLY=($(compgen -W "$(__pgbackrest_stanza_values)" -- ${cur}))
187217
return 0;;
188218
--output)
189-
COMPREPLY=($(compgen -W "$(__pgbackrest_command_options_values_output)" -- ${cur}))
190-
return 0;;
219+
case ${COMP_WORDS[1]} in
220+
verify)
221+
COMPREPLY=($(compgen -W "$(__pgbackrest_command_options_values_output_verify)" -- ${cur}))
222+
return 0;;
223+
*)
224+
COMPREPLY=($(compgen -W "$(__pgbackrest_command_options_values_output)" -- ${cur}))
225+
return 0;;
226+
esac;;
191227
--buffer-size)
192228
COMPREPLY=($(compgen -W "$(__pgbackrest_command_options_values_buffer_size)" -- ${cur}))
193229
return 0;;
230+
--type)
231+
case ${COMP_WORDS[1]} in
232+
info)
233+
COMPREPLY=($(compgen -W "$(__pgbackrest_command_options_values_backup_types)" -- ${cur}))
234+
return 0;;
235+
*)
236+
COMPREPLY=($(compgen -W "$(__pgbackrest_command_options_values)" -- ${cur}))
237+
return 0;;
238+
esac;;
194239
*)
195240
if [[ ${prev} =~ ${arg_regex} ]]; then
196241
COMPREPLY=($(compgen -W "$(__pgbackrest_command_options_values)" -- ${cur}))

0 commit comments

Comments
 (0)