-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_completion
executable file
·57 lines (50 loc) · 1.77 KB
/
create_completion
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
#!/usr/bin/env bash
# @file create_completion
# Create a bash completion script for vke using cli_taxo
# @author Alister Lewis-Bowen <alister@lewis-bowen.org>
[[ -n $DEBUG ]] && set -x
set -eou pipefail
DIR="$PWD"
vke_cli_url() {
case "$OSTYPE" in
## Pulled from `curl https://api.vke.cloud.vmware.com/v1/cli | jq .latest``
darwin*) echo 'https://s3-us-west-2.amazonaws.com/cascade-cli-download/pre-prod-us-west-2/latest/mac/vke' ;;
linux*) echo 'https://s3-us-west-2.amazonaws.com/cascade-cli-download/pre-prod-us-west-2/latest/linux64/vke' ;;
msys*) echo 'https://s3-us-west-2.amazonaws.com/cascade-cli-download/pre-prod-us-west-2/latest/windows64/vke.exe' ;;
*) return 1;;
esac
return 0
}
install_vke_cli() {
echo
echo "Installing vke CLI... "
curl "$(vke_cli_url)" > ./vke && chmod 755 ./vke
return 0
}
install_cli_taxo() {
echo
echo "Installing cli_taxo... "
curl -O https://raw.githubusercontent.com/ali5ter/cli_taxo/master/cli_taxo.py
curl -O https://raw.githubusercontent.com/ali5ter/cli_taxo/master/bash_completion.tmpl
curl -O https://raw.githubusercontent.com/ali5ter/cli_taxo/master/requirements.txt
pip install --user -r requirements.txt
chmod 755 cli_taxo.py
return 0
}
generate_autocomplete_script() {
echo
echo "Generating autocomplete script... "
./cli_taxo.py vke \
--commands-token '^COMMANDS:$' \
--commands-filter '^\s\s\s\s\s(?!-)(\S[^,\s]+)' \
--options-token 'OPTIONS:$' \
--options-filter '^\s\s\s(-\S[^,\s]+)|\s(-\S[^,\s]+)\s\s' \
-o bash -O > "$DIR/vke_bash_completion.sh"
return 0
}
cd /tmp || exit 1
install_vke_cli
install_cli_taxo
export PATH="$PATH:."
generate_autocomplete_script
cd "$PWD" || exit 1