/
completion_func.go
91 lines (83 loc) · 2.37 KB
/
completion_func.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package topics
const (
bashCompletionFunc = `
__barry_get_config() {
__barry_config=$(eval $COMP_LINE --get-config-filename)
}
__internal_list_projects() {
local barry_output out
__barry_get_config
if barry_output=$(barry --config $__barry_config project list --basic 2>/dev/null); then
out=($(echo "${barry_output}"))
COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) )
fi
}
__internal_list_files() {
local barry_output out project_name
project_name="$1"
__barry_get_config
if barry_output=$(barry --config $__barry_config project list "$project_name" --basic 2>/dev/null); then
out=($(echo "${barry_output}"))
COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) )
fi
}
__internal_list_destinations() {
local barry_output out
__barry_get_config
if barry_output=$(barry --config $__barry_config get destinations --basic 2>/dev/null); then
out=($(echo "${barry_output}"))
COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) )
fi
}
__internal_project_set() {
local prev_prev_prev=${COMP_WORDS[COMP_CWORD-3]}
if [ "$prev" = "set" ]; then
out=(backup_every local_expiration remote_expiration)
COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) )
elif [ "$prev_prev_prev" = "set" ]; then
__internal_list_projects
fi
}
__internal_file_download() {
local prev_prev=${COMP_WORDS[COMP_CWORD-2]}
if [ "$prev" = "download" ]; then
__internal_list_projects
elif [ "$prev_prev" = "download" ]; then
__internal_list_files $prev
fi
}
__internal_file_push() {
local prev_prev=${COMP_WORDS[COMP_CWORD-2]}
local prev3=${COMP_WORDS[COMP_CWORD-3]}
if [ "$prev" = "push" ]; then
__internal_list_projects
elif [ "$prev_prev" = "push" ]; then
__internal_list_files $prev
elif [ "$prev3" = "push" ]; then
__internal_list_destinations
fi
}
__barry_custom_func() {
case ${last_command} in
barry_project_list | barry_project_infos | barry_project_archive | barry_project_unarchive | barry_file_upload)
__internal_list_projects
return
;;
barry_project_set)
__internal_project_set
return
;;
barry_file_download)
__internal_file_download
return
;;
barry_file_push)
__internal_file_push
return
;;
*)
;;
esac
}
`
)