-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplete.sh
More file actions
executable file
·178 lines (169 loc) · 6.1 KB
/
complete.sh
File metadata and controls
executable file
·178 lines (169 loc) · 6.1 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
_code-push()
{
function cacheAndGetAppList() {
if [ ! -e ~/.code-push-cache/.applist ] || test `find ~/.code-push-cache/.applist -mmin +120` ; then
code-push app list --format json | grep name | sed s/\ \ \ \ \"name\"\:\ \"//g | sed s/\",//g > ~/.code-push-cache/.applist
fi
echo $(cat ~/.code-push-cache/.applist)
}
function cacheAndGetDeploymentList() {
local deploymentFile
deploymentFile=~/.code-push-cache/$1
if [ ! -e $deploymentFile ] || test `find ${deploymentFile} -mmin +120` ; then
code-push deployment list $1 --format json | grep name | sed s/\ \ \ \ \"name\"\:\ \"//g | sed s/\",//g > $deploymentFile
fi
echo $(cat $deploymentFile)
}
if [ ! -e ~/.code-push-cache ] ; then
mkdir ~/.code-push-cache
fi
local cur prev opts base_command
COMPREPLY=()
curr=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
base_command=${COMP_WORDS[1]}
if [ $prev == "--format" ] ; then
opts="json table"
elif [ $COMP_CWORD -eq 1 ] ; then
opts="access-key app collaborator debug deployment link login logout patch promote register release release-cordova release-react rollback session whoami"
else
case "$base_command" in
"access-key")
if [ $COMP_CWORD -eq 2 ] ; then
opts="add remove patch list"
elif [ $COMP_CWORD -gt 2 ] ; then
opts="--format"
fi
;;
"app")
if [ $COMP_CWORD -eq 2 ] ; then
opts="add remove rename list transfer"
elif [ $COMP_CWORD -eq 3 ] ; then
if ([ "${COMP_WORDS[2]}" = "list" ] || [ "${COMP_WORDS[2]}" = "ls" ]) && [[ $curr == "-"* ]] ; then
opts="--format"
fi
fi
;;
"collaborator")
if [ $COMP_CWORD -eq 2 ] ; then
opts="add remove list"
elif [ $COMP_CWORD -eq 4 ] ; then
if ([ "${COMP_WORDS[2]}" = "list" ] || [ "${COMP_WORDS[2]}" = "ls" ]) && [[ $curr == "-"* ]] ; then
opts="--format"
fi
fi
;;
"debug")
if [ $COMP_CWORD -eq 2 ] ; then
opts="ios android"
fi
;;
"deployment")
if [ $COMP_CWORD -eq 2 ] ; then
opts="add clear remove rename list history"
elif [ $COMP_CWORD -eq 3 ] ; then
opts=$(cacheAndGetAppList)
elif [ $COMP_CWORD -eq 4 ] ; then
if ([ "${COMP_WORDS[2]}" = "list" ] || [ "${COMP_WORDS[2]}" = "ls" ]) && [[ $curr == "-"* ]] ; then
opts="--displayKeys --format"
elif [ "${COMP_WORDS[2]}" = "history" ] || [ "${COMP_WORDS[2]}" = "h" ] || [ "${COMP_WORDS[2]}" = "rename" ] ; then
opts=$(cacheAndGetDeploymentList ${COMP_WORDS[3]})
fi
elif [ $COMP_CWORD -gt 4 ] ; then
if ([ "${COMP_WORDS[2]}" = "history" ] || [ "${COMP_WORDS[2]}" = "h" ]) && [[ $curr == "-"* ]] ; then
opts="--displayAuthor --format"
fi
fi
;;
"login")
if [[ $curr == "-"* ]] ; then
opts="--proxy --noproxy --accessKey"
fi
;;
"release")
if [ $COMP_CWORD -eq 2 ] ; then
opts=$(cacheAndGetAppList)
elif [ $COMP_CWORD -gt 4 ] ; then
if [[ $curr == "-"* ]] ; then
opts="--deploymentName --description --disabled --mandatory --rollout"
elif [ $prev == "--deploymentName" ] || [ $prev == "-d" ] ; then
opts=$(cacheAndGetDeploymentList ${COMP_WORDS[2]})
fi
fi
;;
"release-react")
if [ $COMP_CWORD -eq 2 ] ; then
opts=$(cacheAndGetAppList)
elif [ $COMP_CWORD -eq 3 ] ; then
opts="android ios"
elif [ $COMP_CWORD -gt 3 ] ; then
if [[ $curr == "-"* ]] ; then
opts="--bundleName --deploymentName --description --development --disabled --entryFile --mandatory --sourcemapOutput --targetBinaryVersion --rollout"
elif [ $prev == "--deploymentName" ] || [ $prev == "-d" ] ; then
opts=$(cacheAndGetDeploymentList ${COMP_WORDS[2]})
fi
fi
;;
"release-cordova")
if [ $COMP_CWORD -eq 2 ] ; then
opts=$(cacheAndGetAppList)
elif [ $COMP_CWORD -eq 3 ] ; then
opts="android ios"
elif [ $COMP_CWORD -gt 3 ] ; then
if [[ $curr == "-"* ]] ; then
opts="--deploymentName --description --mandatory --targetBinaryVersion --rollout --build"
elif [ $prev == "--deploymentName" ] || [ $prev == "-d" ] ; then
opts=$(cacheAndGetDeploymentList ${COMP_WORDS[2]})
fi
fi
;;
"patch")
if [ $COMP_CWORD -eq 2 ] ; then
opts=$(cacheAndGetAppList)
elif [ $COMP_CWORD -gt 3 ] ; then
if [[ $curr == "-"* ]] ; then
opts="--label --mandatory --description --rollout --disabled --targetBinaryVersion"
elif [ $prev == "--deploymentName" ] || [ $prev == "-d" ] ; then
opts=$(cacheAndGetDeploymentList ${COMP_WORDS[2]})
fi
fi
;;
"promote")
if [ $COMP_CWORD -eq 2 ] ; then
opts=$(cacheAndGetAppList)
elif [ $COMP_CWORD -gt 3 ] ; then
if [[ $curr == "-"* ]] ; then
opts="--description --disabled --mandatory --rollout --targetBinaryVersion"
elif [ $prev == "--deploymentName" ] || [ $prev == "-d" ] ; then
opts=$(cacheAndGetDeploymentList ${COMP_WORDS[2]})
fi
fi
;;
"rollback")
if [ $COMP_CWORD -eq 2 ] ; then
opts=$(cacheAndGetAppList)
elif [ $COMP_CWORD -gt 4 ] && [[ $curr == "-"* ]] ; then
opts="--targetRelease"
fi
;;
"session")
if [ $COMP_CWORD -eq 2 ] ; then
opts="remove list"
elif [ $COMP_CWORD -eq 3 ] ; then
if ([ "${COMP_WORDS[2]}" = "list" ] || [ "${COMP_WORDS[2]}" = "ls" ]) && [[ $curr == "-"* ]] ; then
opts="--format"
fi
fi
;;
*)
;;
esac
fi
if [ ! -z "$opts" ] ; then
COMPREPLY=($(compgen -W "$opts" -- $curr))
else
COMPREPLY=($(compgen -f -d -- $curr))
fi
return 0
}
complete -F _code-push code-push