Skip to content

Commit b6e42c3

Browse files
author
Graham Allan
committed
gallan: enable basic tab completion for orc, that can provide all available options, and suggest an application and environment.
1 parent 66aeec2 commit b6e42c3

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

Rakefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ task :package do
3030
sh 'mkdir -p build/package/usr/local/bin/'
3131
sh 'cp -r bin/* build/package/usr/local/bin/'
3232

33+
sh 'mkdir -p build/package/etc'
34+
sh 'cp -r etc/* build/package/etc'
35+
3336
arguments = [
3437
'--description', 'orchestration tool',
3538
'--url', 'https://github.com/tim-group/orc',

etc/bash_completion.d/orc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Provides bash completion for the orc command
2+
# Currently supports completing all long options, environment and application.
3+
#
4+
# Potential improvements:
5+
# * the set of options should be generated by orc code, so it remains in sync when new options are added
6+
# * once --environment has been specified, filter applications to only those in that environment, and vice-versa
7+
8+
_orc()
9+
{
10+
CMDB_HOME=$HOME/.cmdb
11+
12+
local cur=${COMP_WORDS[COMP_CWORD]}
13+
local prev=${COMP_WORDS[COMP_CWORD-1]}
14+
15+
case "$prev" in
16+
-e|--environment)
17+
local all_environments="$(ls -1 $CMDB_HOME)"
18+
COMPREPLY=( $(compgen -W "${all_environments}" -- "$cur" ))
19+
return 0
20+
;;
21+
-a|--application)
22+
local all_applications="$(find $CMDB_HOME -name "*.yaml" -type f -exec basename {} ';' | sed -e 's/.yaml//g' | sort | uniq )"
23+
COMPREPLY=( $(compgen -W "${all_applications}" -- "$cur" ))
24+
return 0
25+
;;
26+
esac
27+
28+
COMPREPLY=( $(compgen -W "--debug --environment --promote-from --application\
29+
--version --group --status --deploy --install \
30+
--limited-install --swap --resolve --promote" -- "$cur") )
31+
32+
}
33+
complete -F _orc orc

0 commit comments

Comments
 (0)