Skip to content

Commit 38c98c4

Browse files
committed
add nova-manage bash completion script
Change-Id: I856349fb0b31f32ec4570c74ebceb3563fa22547
1 parent 8637f71 commit 38c98c4

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

Authors

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Devdeep Singh <[email protected]>
5858
Devendra Modium <[email protected]>
5959
Devin Carlen <[email protected]>
6060
Dina Belova <[email protected]>
61+
Dominik Heidler <[email protected]>
6162
Don Dugger <[email protected]>
6263
Donal Lafferty <[email protected]>
6364
Dong-In David Kang <[email protected]>

bin/nova-manage

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,18 @@ def main():
16921692
print "\t%s" % k
16931693
sys.exit(2)
16941694
category = argv.pop(0)
1695+
if category == "bash-completion":
1696+
if len(argv) < 1:
1697+
print " ".join([k for (k, v) in CATEGORIES])
1698+
else:
1699+
query_category = argv.pop(0)
1700+
matches = lazy_match(query_category, CATEGORIES)
1701+
# instantiate the command group object
1702+
category, fn = matches[0]
1703+
command_object = fn()
1704+
actions = methods_of(command_object)
1705+
print " ".join([k for (k, v) in actions])
1706+
sys.exit(0)
16951707
matches = lazy_match(category, CATEGORIES)
16961708
# instantiate the command group object
16971709
category, fn = matches[0]

tools/nova-manage.bash_completion

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# bash completion for openstack nova-manage
2+
3+
_nova_manage_opts="" # lazy init
4+
_nova_manage_opts_exp="" # lazy init
5+
6+
# dict hack for bash 3
7+
_set_nova_manage_subopts () {
8+
eval _nova_manage_subopts_"$1"='$2'
9+
}
10+
_get_nova_manage_subopts () {
11+
eval echo '${_nova_manage_subopts_'"$1"'#_nova_manage_subopts_}'
12+
}
13+
14+
_nova_manage()
15+
{
16+
local cur prev subopts
17+
COMPREPLY=()
18+
cur="${COMP_WORDS[COMP_CWORD]}"
19+
prev="${COMP_WORDS[COMP_CWORD-1]}"
20+
21+
if [ "x$_nova_manage_opts" == "x" ] ; then
22+
_nova_manage_opts="`nova-manage bash-completion 2>/dev/null`"
23+
_nova_manage_opts_exp="`echo $_nova_manage_opts | sed -e "s/\s/|/g"`"
24+
fi
25+
26+
if [[ " `echo $_nova_manage_opts` " =~ " $prev " ]] ; then
27+
if [ "x$(_get_nova_manage_subopts "$prev")" == "x" ] ; then
28+
subopts="`nova-manage bash-completion $prev 2>/dev/null`"
29+
_set_nova_manage_subopts "$prev" "$subopts"
30+
fi
31+
COMPREPLY=($(compgen -W "$(_get_nova_manage_subopts "$prev")" -- ${cur}))
32+
elif [[ ! " ${COMP_WORDS[@]} " =~ " "($_nova_manage_opts_exp)" " ]] ; then
33+
COMPREPLY=($(compgen -W "${_nova_manage_opts}" -- ${cur}))
34+
fi
35+
return 0
36+
}
37+
complete -F _nova_manage nova-manage

0 commit comments

Comments
 (0)