-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorient-completion
More file actions
104 lines (96 loc) · 3.09 KB
/
orient-completion
File metadata and controls
104 lines (96 loc) · 3.09 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
__orient_cmds="add agent-pools branch build check checkout clean-cache clone component config credentials deliver
diff docker doctor fetch from-materialized hash help list log lookup merge pull push rebase rebuild-publications
refresh repo report reviews rm selfupdate setup stash status suppress tps_report trigger-lkg vetting visualize"
__orient_workspace() {
local dir=$PWD
while [ $dir != "/" ]; do
if [ -f ${dir}/.orient-ws ]; then
echo $dir
return 0
fi
dir=$(dirname $dir)
done
return 1
}
__orient_repos() {
# Workspace: /home/lego/code/citrix-linux
local workspace=$(__orient_workspace)
if [ ! $? ] ; then
return 1
else
cat ${workspace}/orient/components/world.json | jq -j '.components[].name+" "'
return 0
fi
}
__orient_repo_cmds="branch delete fetch for-each hash materialize optimize ovb-lookup reset show"
__orient_repo() {
local workspace=$(__orient_workspace)
if [ "x${workspace}" == "x" ] ; then
return 1
else
echo "-h --help ${__orient_repo_cmds[@]}"
return 0
fi
}
__orient_setup_targets() {
local workspace=$(__orient_workspace)
if [ -f setup_targets ]; then
cat setup_targets
else
__orient_repos
fi
}
_orient(){
# echo "repo: 4=$4, 3=$3, 2=$2, 1=$1, 0=$0"
if [ "$3" == "add" ]; then
COMPREPLY=( $(compgen -W "$(__orient_repos)" -- $2) )
elif [ "$3" == "list" ]; then
COMPREPLY=( $(compgen -W "$(__orient_repos)" -- $2) )
elif [ "$3" == "setup" ]; then
# TODO: append slash to all the repos, and no space
COMPREPLY=( $(compgen -W "$(__orient_setup_targets)" -- $2) )
elif [ "$3" == "repo" ]; then
# check if there is a repo command after `orient repo`. if yes, present list of repo names. otherwise, present list of repo commands
if [ "$4" == "" ]; then
# echo "repo: 4=<empty>"
COMPREPLY=( $(compgen -W "$__orient_repo_cmds" -- $2) )
else
# echo "get list of repos"
COMPREPLY=( $(compgen -W "$(__orient_repos)" -- $2) )
fi
else
COMPREPLY=( $(compgen -W "$__orient_cmds" -- $2) )
fi
}
complete -F _orient orient
# TODO: move this to somewhere else - it's orient, but not about completions
orient() {
local argc=$#
local argv=($@)
if [ $argc -eq 1 ]; then
case ${argv[0]} in
"branch")
local workspace=$(__orient_workspace)
if [ -z ${workspace} ] ; then
local red='\e[0;31m'
local reset='\e[0m'
echo -e "${red}You're not in orient workspace${reset}"
else
cd $workspace/orient_virtual_branches
git branch
cd $OLDPWD
fi
;;
"deliver")
local workspace=$(__orient_workspace)
command orient deliver --yes --security-ok --delete-vbranch --rebase
;;
*)
command orient $@
;;
esac
else
command orient $@
fi
}
# vim: filetype=bash