311 lines
9.6 KiB
Plaintext
Raw Normal View History

# bash completion for puppet -*- shell-script -*-
2011-02-23 21:14:35 +01:00
_puppet_logdest()
{
2011-11-09 23:28:11 +02:00
if [[ -z $cur ]]; then
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W 'syslog console /' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
else
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W 'syslog console' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
_filedir
fi
}
_puppet_digest()
{
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W 'MD5 MD2 SHA1 SHA256' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
}
_puppet_certs()
{
local puppetca="puppet cert"
2011-02-23 21:22:18 +01:00
PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type puppetca &>/dev/null \
&& puppetca=puppetca
2012-07-22 19:35:03 +03:00
2011-02-23 21:42:08 +01:00
if [[ "$1" = '--all' ]]; then
cert_list=$( $puppetca --list --all | sed -e 's/^[+-]\?\s*\(\S\+\)\s\+.*$/\1/' )
2011-02-23 21:14:35 +01:00
else
cert_list=$( $puppetca --list )
2011-02-23 21:14:35 +01:00
fi
COMPREPLY+=( $( compgen -W "$cert_list" -- "$cur" ) )
2011-02-23 21:14:35 +01:00
}
_puppet_types()
{
puppet_types=$( puppet describe --list | sed -e 's/^\(\S\+\).*$/\1/' )
COMPREPLY+=( $( compgen -W "$puppet_types" -- "$cur" ) )
2011-02-23 21:14:35 +01:00
}
_puppet_references()
{
local puppetdoc="puppet doc"
2011-02-23 21:22:18 +01:00
PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type puppetdoc &>/dev/null \
&& puppetdoc=puppetdoc
2011-02-23 21:14:35 +01:00
puppet_doc_list=$( $puppetdoc --list | sed -e 's/^\(\S\+\).*$/\1/' )
COMPREPLY+=( $( compgen -W "$puppet_doc_list" -- "$cur" ) )
2011-02-23 21:14:35 +01:00
}
_puppet()
{
local cur prev words cword
_init_completion || return
2011-02-23 21:14:35 +01:00
local xspec helpopts command subcommand
2011-02-23 21:14:35 +01:00
case $prev in
--help)
return 0
;;
esac
case ${words[0]} in
2011-02-23 21:14:35 +01:00
puppetmasterd)
command=master
2011-02-23 21:14:35 +01:00
;;
puppetd)
command=agent
2011-02-23 21:14:35 +01:00
;;
puppetca)
command=cert
2011-02-23 21:14:35 +01:00
;;
ralsh)
command=resource
2011-02-23 21:14:35 +01:00
;;
puppetrun)
command=kick
2011-02-23 21:14:35 +01:00
;;
puppetqd)
command=queue
2011-02-23 21:14:35 +01:00
;;
filebucket)
command=filebucket
2011-02-23 21:14:35 +01:00
;;
puppetdoc)
command=doc
2011-02-23 21:14:35 +01:00
;;
pi)
command=describe
2011-02-23 21:14:35 +01:00
;;
puppet)
case ${words[1]} in
2011-02-23 21:14:35 +01:00
agent|apply|cert|describe|doc|filebucket|kick|master|queue|resource)
command=${words[1]}
2011-02-23 21:14:35 +01:00
;;
*.pp|*.rb|-*)
command=apply
2011-02-23 21:14:35 +01:00
;;
*)
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W 'agent apply cert describe doc \
filebucket kick master queue resource' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
return 0
;;
esac
esac
case $command in
2011-02-23 21:14:35 +01:00
agent)
case $prev in
--fqdn)
return 0
2011-02-23 21:24:53 +01:00
;;
2011-02-23 21:14:35 +01:00
--logdest)
_puppet_logdest
return 0
2011-02-23 21:24:53 +01:00
;;
2011-02-23 21:14:35 +01:00
--serve)
# From /usr/lib/ruby/1.8/puppet/network/handler/
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W 'ca filebucket fileserver master \
report runner status' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
return 0
2011-02-23 21:24:53 +01:00
;;
2011-02-23 21:14:35 +01:00
--digest)
_puppet_digest
return 0
2011-02-23 21:24:53 +01:00
;;
2011-02-23 21:14:35 +01:00
--waitforcert)
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W '0 15 30 60 120' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
return 0
2011-02-23 21:24:53 +01:00
;;
2011-02-23 21:14:35 +01:00
*)
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W '--daemonize --no-daemonize \
2011-02-23 21:22:18 +01:00
--debug --detailed-exitcodes --disable --enable \
--help --fqdn --logdest --onetime --serve --test \
--noop --digest --fingerprint --version --verbose \
2011-02-23 21:42:08 +01:00
--waitforcert --no-client' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
return 0
esac
;;
apply)
case $prev in
--logdest)
_puppet_logdest
return 0
;;
*)
if [[ "$cur" == -* ]]; then
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W '--help --version --debug \
2011-02-23 21:22:18 +01:00
--verbose --execute --detailed-exitcodes \
2011-02-23 21:42:08 +01:00
--logdest' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
else
_filedir
fi
return 0
esac
2012-07-22 19:35:03 +03:00
;;
2011-02-23 21:14:35 +01:00
cert)
case $prev in
--digest)
_puppet_digest
return 0
;;
*)
subcommand=$prev
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W '--digest --debug --verbose' \
2011-02-23 21:22:18 +01:00
-- "$cur" ) )
case $subcommand in
2011-02-23 21:14:35 +01:00
--generate)
_known_hosts_real "$cur"
return 0
;;
--clean|--fingerprint|--revoke|--verify)
COMPREPLY+=( $( compgen -W '--all' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
_puppet_certs --all
return 0
;;
--sign)
COMPREPLY+=( $( compgen -W '--all' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
_puppet_certs
return 0
;;
--list|--print)
COMPREPLY+=( $( compgen -W '--all' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
return 0
;;
*)
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W '--clean --generate \
2011-02-23 21:22:18 +01:00
--help --list --print --fingerprint --revoke \
2011-02-23 21:42:08 +01:00
--sign --version --verify' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
return 0
esac
esac
2012-07-22 19:35:03 +03:00
;;
2011-02-23 21:14:35 +01:00
describe)
if [[ "$cur" == -* ]]; then
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W '--help --short --providers --list \
--meta' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
else
_puppet_types
fi
return 0
2012-07-22 19:35:03 +03:00
;;
2011-02-23 21:14:35 +01:00
doc)
case $prev in
--outputdir)
_filedir -d
return 0
;;
--mode)
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W 'text trac pdf rdoc' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
return 0
;;
--reference)
_puppet_references
return 0
;;
*)
if [[ "$cur" == -* ]]; then
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W '--all --help --outputdir \
--mode --reference --charset --list' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
else
_filedir
fi
return 0
esac
2012-07-22 19:35:03 +03:00
;;
2011-02-23 21:14:35 +01:00
filebucket)
case $prev in
--server)
_known_hosts_real "$cur"
2011-02-23 21:14:35 +01:00
return 0
;;
--bucket)
_filedir -d
return 0
;;
*)
if [[ "$cur" == -* ]]; then
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W '--help --version --debug \
--verbose --local --remote --server --bucket' \
2011-02-23 21:22:18 +01:00
-- "$cur" ) )
2011-02-23 21:14:35 +01:00
else
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W 'backup get restore' \
2011-02-23 21:22:18 +01:00
-- "$cur" ) )
2011-02-23 21:14:35 +01:00
_filedir
fi
return 0
esac
2012-07-22 19:35:03 +03:00
;;
2011-02-23 21:14:35 +01:00
kick)
case $prev in
--class)
return 0
;;
--host)
2012-07-22 19:35:03 +03:00
_known_hosts_real "$cur"
2011-02-23 21:14:35 +01:00
return 0
;;
--tag)
return 0
;;
*)
if [[ "$cur" == -* ]]; then
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W '--all --class --debug \
2011-02-23 21:22:18 +01:00
--foreground --help --host --no-fqdn \
2011-02-23 21:42:08 +01:00
--ignoreschedules --tag --test --ping' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
else
_known_hosts_real "$cur"
fi
return 0
esac
2012-07-22 19:35:03 +03:00
;;
2011-02-23 21:14:35 +01:00
master)
case $prev in
--logdest)
_puppet_logdest
return 0
;;
*)
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W '--daemonize --no-daemonize \
--debug --help --logdest --verbose --version' \
2011-02-23 21:22:18 +01:00
-- "$cur" ) )
2011-02-23 21:14:35 +01:00
return 0
esac
2012-07-22 19:35:03 +03:00
;;
2011-02-23 21:14:35 +01:00
queue)
case $prev in
--logdest)
_puppet_logdest
return 0
;;
*)
if [[ "$cur" == -* ]]; then
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W '--help --version --debug \
2011-02-23 21:22:18 +01:00
--verbose --execute --detailed-exitcodes \
2011-02-23 21:42:08 +01:00
--logdest' -- "$cur" ) )
2011-02-23 21:14:35 +01:00
else
_filedir
fi
return 0
esac
2012-07-22 19:35:03 +03:00
;;
2011-02-23 21:14:35 +01:00
resource|*)
2011-02-23 21:42:08 +01:00
COMPREPLY=( $( compgen -W '--help --version --debug --verbose' \
2011-02-23 21:22:18 +01:00
-- "$cur" ) )
2011-02-23 21:14:35 +01:00
return 0
2012-07-22 19:35:03 +03:00
;;
2011-02-23 21:14:35 +01:00
esac
} &&
2012-07-22 19:35:03 +03:00
complete -F _puppet puppetmasterd puppetd puppetca ralsh puppetrun puppetqd filebucket puppetdoc puppet
2011-02-23 21:14:35 +01:00
# ex: ts=4 sw=4 et filetype=sh