Skip to content

Instantly share code, notes, and snippets.

@mschuerig
Created June 16, 2012 15:21
Show Gist options
  • Save mschuerig/2941652 to your computer and use it in GitHub Desktop.
Save mschuerig/2941652 to your computer and use it in GitHub Desktop.
Bash completion for cucumber
__cucumbercomp() {
local cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $( compgen -W "$1" -- "$cur" ) )
}
__cucumbertags() {
sed -r -n 's/^\s*(((@[[:alnum:]]+)\s?)+).*$/\1/p' features/**/*.feature \
| sed -r 's/\s+/\n/'
}
__cucumbernames() {
sed -r -n 's/^\s*(Funktionalität|Szenario):\s*(.+)\s*$/\2/p' features/**/*.feature
}
__cucumberprofiles() {
local cf
for d in . config; do
cf="${d}/cucumber.yml"
if [ -f "$cf" ]; then
sed -r '/^\s*<%/,/^\s*%>/ d' "$cf" \
| sed -r -n 's/^([^:]+):.*/\1/p'
fi
done
}
_cucumber() {
local cur prev
_get_comp_words_by_ref cur prev
if [[ "$cur" == -* ]]; then
__cucumbercomp "-r --require --i18n -f --format -o --out \
-t --tags -n --name -e --exclude -p --profile -P --no-profile \
-c --color --no-color -d --dry-run -a --autoformat -m --no-multiline \
-s --no-source -i --no-snippets -q --quiet -b --backtrace \
-S --strict -w --wip -v --verbose -g --guess -l --lines \
-x --expand --drb --no-drb --port --dotcucumber \
--version -h --help"
else
case "$prev" in
-r|--require)
;;
--i18n)
;;
-f|--format)
__cucumbercomp "html json json_pretty junit pretty progress rerun stepdefs usage"
;;
-o|--out)
_filedir
return 0
;;
-t|--tags|@*,|~@*,)
__cucumbercomp "$(__cucumbertags)"
;;
-n|--name)
# local -a names=$(__cucumbernames)
# __cucumbercomp ${names[@]}
;;
-e|--exclude)
;;
-p|--profile)
__cucumbercomp "$(__cucumberprofiles)"
;;
-a|--autoformat)
_filedir -d
;;
-l|--lines)
;;
--port)
;;
--dotcucumber)
_filedir -d
;;
esac
fi
}
complete -o default -F _cucumber cucumber
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment