-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgitlab.auto
executable file
·71 lines (65 loc) · 2.75 KB
/
gitlab.auto
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
#!/usr/bin/env bash
# -------------------------------------------------------------------------------
#
# Copyright (c) 2016 Slava Vladyshevsky. All rights reserved.
# Licensed under the MIT License. See LICENSE file in the project root.
#
# Author: Slava Vladyshevsky <slava.vladyshevsky(a)gmail.com>
# Project: DevOps Automation
#
# Bash auto-completion for the gitlab tool
#
# -------------------------------------------------------------------------------
# see https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html
# $1: is the name of the command whose arguments are being completed
# $2: is the word being completed, equal to ${COMP_WORDS[COMP_CWORD]}
# $3: is the word preceding the word being completed, equal to ${COMP_WORDS[COMP_CWORD-1]}
_comp_gitlab() {
# the basic CLI objects
local objects="group project user"
local args=""
COMPREPLY=()
if [[ "${1} ${objects}" =~ ${3} ]] ; then
case "${3}" in
group) args="list dir add create del remove users members adduser useradd deluser userdel" ;;
project|user) args="list dir add create del remove" ;;
${1}) args=${objects} ;;
*) return 0 ;;
esac
else
case "${COMP_WORDS[1]}-${COMP_WORDS[2]}" in
group-list|group-dir) args="--pattern --format" ;;
group-add|group-create) args="--group --description" ;;
group-del|group-remove) args="--group" ;;
group-users|group-members) args="--group --format" ;;
group-adduser|group-useradd) args="--group --login --access" ;;
group-deluser|group-userdel) args="--group --login" ;;
project-list|project-dir) args="--group --pattern --format" ;;
project-add|project-create) args="--project --group --description" ;;
project-del|project-remove) args="--project --group" ;;
user-list|user-dir) args="--pattern --format" ;;
user-add|user-create) args="--login --name --mail --org" ;;
user-del|user-remove) args="--login" ;;
*) return 0 ;;
esac
fi
# complete the choice for some of the common arguments
if [[ ${3} == --* ]] ; then
local IFS=$'\n\t'
case "${3}" in
--org) args=$(${1%/*}/ldap org list 2>/dev/null) ;;
--group) args=$(${1} group list --format list 2>/dev/null) ;;
--login) args=$(${1} user list --format list 2>/dev/null) ;;
--access) args=$'guest\treporter\tdeveloper\tmaster\towner' ;;
--format) args=$'list\ttable' ;;
*) return 0 ;;
esac
COMPREPLY=($(compgen -W "${args[*]}" -- ${2}))
# escaping spaces and other unsafe characters
COMPREPLY=($(printf "%q\n" "${COMPREPLY[@]}"))
return 0
fi
COMPREPLY=($(compgen -W "${args[*]}" -- ${2}))
return 0
}
complete -F _comp_gitlab gitlab