-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfigure.sh
executable file
·166 lines (148 loc) · 3.64 KB
/
configure.sh
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
readonly APP_NAME=$(basename $BASH_SOURCE)
readonly DIR_NAME=$(dirname $BASH_SOURCE)
. $DIR_NAME/lib/config_accessor.sh
. $DIR_NAME/lib/filter_manager.sh
function usage() {
cat <<- EOF
Usage:
$APP_NAME list
$APP_NAME add <github instance url> [<access token>]
$APP_NAME rm <github instance url>
$APP_NAME activate <github instance url>
$APP_NAME deactivate <github instance url>
$APP_NAME token update <github instance url> [<new token>]
$APP_NAME filters
Normally, the most popular github instance is https://github.com
The other instances are github enterprise instances.
Examples:
List all configurations:
$APP_NAME list
Add a new configuration:
$APP_NAME add https://github.mycompany.com
Deactivate a configuration:
$APP_NAME deactivate https://github.mycompany.com
Remove a configuration:
$APP_NAME rm https://github.mycompany.com
Reset token
$APP_NAME token update github.mycompany.com new_token
EOF
}
function route_command() {
local cmd=$1
case $cmd in
"list")
list_configs
;;
"add")
local config_name=$2
local access_token=$3
add_config $config_name $access_token
;;
"rm")
local config_name=$2
remove_config $config_name
;;
"activate")
local config_name=$2
activate_config $config_name
;;
"deactivate")
local config_name=$2
deactivate_config $config_name
;;
"token")
local token_cmd=$2
local config_name=$3
local access_token=$4
route_token_command $token_cmd $config_name $access_token
;;
"filters")
route_filters_command $2 $3 $4 $5
;;
*)
if [[ $cmd ]]; then
echo "unknown command $cmd"
fi
usage
;;
esac
}
function filters_usage() {
cat <<- EOF
Usage:
$APP_NAME filters list
$APP_NAME filters add <github instance url> <filter name>
$APP_NAME filters rm <filter name>
$APP_NAME filters activate <filter name>
$APP_NAME filters deactivate <filter name>
$APP_NAME filters add-project <filter name> <github project name> <include|exclude>
$APP_NAME filters list-projects <filter name>
Examples:
Add filter groups:
$APP_NAME filters add https://github.com work_projects
Add a few projects to the new filter group:
$APP_NAME filters add-project work_projects redis/redis include
$APP_NAME filters add-project work_projects redis/redis-rb include
EOF
}
function route_filters_command() {
local cmd=$1
case $cmd in
"list")
list_filter_configs
;;
"add")
local config_name=$2
local filter_name=$3
add_filter_config $config_name $filter_name
;;
"rm")
local filter_name=$2
remove_filter_config $filter_name
;;
"activate")
local filter_name=$2
activate_filter_config $filter_name
;;
"deactivate")
local filter_name=$2
deactivate_filter_config $filter_name
;;
"add-project")
local filter_name=$2
local project_name=$3
local filter_type=$4
add_project_filter $filter_name $project_name $filter_type
;;
"rm-project")
local filter_name=$2
local project_name=$3
remove_project_filter $filter_name $project_name
;;
"list-projects")
local filter_name=$2
list_project_filters $filter_name
;;
*)
if [[ $cmd ]]; then
echo "unknown command for filters $cmd"
fi
filters_usage
;;
esac
}
function route_token_command() {
local cmd=$1
local config_name=$2
local access_token=$3
case $cmd in
"update")
update_token $config_name $access_token
;;
"")
usage
;;
esac
}
route_command $1 $2 $3 $4 $5