-
Notifications
You must be signed in to change notification settings - Fork 0
/
_s6opts
147 lines (133 loc) · 3.89 KB
/
_s6opts
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#compdef s6opts
# Copyright (C) 2015-2017 Eric Vidal <eric@obarun.org>
#
# Completion for s6opts
#
# This file is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
#
# This scripts is under License Beerware.
#
# "THE BEERWARE LICENSE" (Revision 42):
# <eric@obarun.org> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return. Eric Vidal http://obarun.org
_s6opts(){
typeset -A opt_args
local ret=1 context state line curcontext="$curcontext"
source /etc/obarun/s6opts.conf
_path() {
local list_dir
list_dir=( $RC_DATABASE_SOURCE/*(-/N:t) )
compadd -X "choose an existing database or create a new one" "$@" -a list_dir
}
_list_available() {
local list_dir
list_dir=( $RC_AVAILABLE/*(-/N:t) )
(( $#list_dir )) && _values services $list_dir && ret=0
}
_list_delete(){
local list_dir
list_dir=( $RC_DATABASE_SOURCE/*/*(-/N:t) )
(( $#list_dir )) && _values services $list_dir #&& ret=0
}
_list_database(){
local list_dir
list_dir=( $RC_DATABASE_COMPILED/*(-/N:t) )
(( $#list_dir )) && _values database_name ${list_dir[@]} && ret=0
}
_list_database_to_compile(){
local list_dir
list_dir=( $RC_DATABASE_SOURCE/*(-/N:t) )
(( $#list_dir )) && _values database_name $list_dir && ret=0
}
_arguments -C \
'1:cmd:->cmds' \
'*:: :->args' \
&& ret=0
case $state in
(cmds)
local commands; commands=(
'add:add a service on service database'
'delete:delete a service on service database'
'compile:compile the service database'
'switch:switch the live service database'
'all:compile and switch the live database'
'update:add a service(s) to the live database'
'list:list of services on live database or from a given name of compiled database'
'list_source:list service enabled on database for compilation'
'verbose:be more or less verbose (permanent change)'
'remove:remove a source service database'
'remove_db:remove a compiled service database'
'which_db:current/previous service database'
'enable:enable a classic service'
'disable:disable a classic service'
'create:create a service'
'edit:edit a service file(s)'
)
_describe -t commands 's6opts command' commands && ret=0
ret=0
;;
(args)
curcontext="${curcontext%:*:*}:s6opts-cmd-$words[1]:"
case $words[1] in
add)
_arguments : \
':database_name:_path' \
'*:services:_list_available'
;;
delete)
_arguments : \
':database_name:_path' \
'*:services:_list_delete'
;;
update)
_arguments : \
'*:services:_list_available'
;;
compile|all)
_arguments : \
':live_database_name:_list_database' \
':compiled_database_name:_list_database_to_compile'
;;
switch|remove_db|list)
local list_dir
list_dir=( $RC_DATABASE_COMPILED/*(-/N:t) )
(( $#list_dir )) && _values database_name $list_dir && ret=0
;;
list_source|remove)
local list_dir
list_dir=( $RC_DATABASE_SOURCE/*(-/N:t) )
(( $#list_dir )) && _values database_name $list_dir && ret=0
;;
which_db)
local list_dir
list_dir=(current previous)
(( $#list_dir )) && _values link_name $list_dir && ret=0
;;
verbose)
_message 'only 0,1,2, or 3 are valid'
;;
enable)
local list_dir
list_dir=( $CLASSIC_AVAILABLE/*(-/N:t) )
(( $#list_dir )) && _values services $list_dir && ret=0
;;
disable)
local list_dir
list_dir=( $LIVE_CLASSIC_PATH/*(-/N:t) )
(( $#list_dir )) && _values services $list_dir && ret=0
;;
edit)
local list_dir
list_dir=( $CLASSIC_AVAILABLE/*(-/N:t) )
list_dir+=( $RC_AVAILABLE/*(-/N:t) )
(( $#list_dir )) && _values services $list_dir && ret=0
;;
esac
;;
esac
return $ret
}
_s6opts "$@"