322 lines
10 KiB
Plaintext
Raw Normal View History

2011-02-23 21:14:35 +01:00
# bash completion for puppet
_puppet_logdest()
{
if [ -z "$cur" ]; then
COMPREPLY=( $( compgen -W "syslog console /" -- "$cur" ) )
else
COMPREPLY=( $( compgen -W "syslog console" -- "$cur" ) )
_filedir
fi
}
_puppet_digest()
{
COMPREPLY=( $( compgen -W "MD5 MD2 SHA1 SHA256" -- "$cur" ) )
}
_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
2011-02-23 21:14:35 +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=( "${COMPREPLY[@]}" $( compgen -W "$cert_list" -- "$cur" ) )
}
_puppet_types()
{
puppet_types=$( puppet describe --list | sed -e 's/^\(\S\+\).*$/\1/' )
2011-02-23 21:14:35 +01:00
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$puppet_types" -- "$cur" ) )
}
_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/' )
2011-02-23 21:14:35 +01:00
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$puppet_doc_list" -- "$cur" ) )
}
have puppetmasterd || have puppetd || have puppetca || have ralsh || \
have puppetrun || have puppetqd || have filebucket || have puppetdoc && \
_puppet()
{
local cur prev xspec helpopts command subcommand
2011-02-23 21:14:35 +01:00
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in
--help)
return 0
;;
esac
case ${COMP_WORDS[0]} in
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 ${COMP_WORDS[1]} in
agent|apply|cert|describe|doc|filebucket|kick|master|queue|resource)
command=${COMP_WORDS[1]}
2011-02-23 21:14:35 +01:00
;;
*.pp|*.rb|-*)
command=apply
2011-02-23 21:14:35 +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:22:18 +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)
COMPREPLY=( $( compgen -W "0 15 30 60 120" -- "$cur" ) )
return 0
2011-02-23 21:24:53 +01:00
;;
2011-02-23 21:14:35 +01:00
*)
2011-02-23 21:22:18 +01:00
COMPREPLY=( $( compgen -W "--daemonize --no-daemonize \
--debug --detailed-exitcodes --disable --enable \
--help --fqdn --logdest --onetime --serve --test \
--noop --digest --fingerprint --version --verbose \
--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:22:18 +01:00
COMPREPLY=( $( compgen -W "--help --version --debug \
--verbose --execute --detailed-exitcodes \
--logdest" -- "$cur" ) )
2011-02-23 21:14:35 +01:00
else
_filedir
fi
return 0
esac
;;
cert)
case $prev in
--digest)
_puppet_digest
return 0
;;
*)
subcommand=$prev
2011-02-23 21:22:18 +01:00
COMPREPLY=( $( compgen -W "--digest --debug --verbose" \
-- "$cur" ) )
case $subcommand in
2011-02-23 21:14:35 +01:00
--generate)
_known_hosts_real "$cur"
return 0
;;
--clean|--fingerprint|--revoke|--verify)
2011-02-23 21:22:18 +01:00
COMPREPLY=( "${COMPREPLY[@]}" $( compgen \
-W "--all" -- "$cur" ) )
2011-02-23 21:14:35 +01:00
_puppet_certs --all
return 0
;;
--sign)
2011-02-23 21:22:18 +01:00
COMPREPLY=( "${COMPREPLY[@]}" $( compgen \
-W "--all" -- "$cur" ) )
2011-02-23 21:14:35 +01:00
_puppet_certs
return 0
;;
--list|--print)
2011-02-23 21:22:18 +01:00
COMPREPLY=( "${COMPREPLY[@]}" $( compgen \
-W "--all" -- "$cur" ) )
2011-02-23 21:14:35 +01:00
return 0
;;
*)
2011-02-23 21:22:18 +01:00
COMPREPLY=( $( compgen -W "--clean --generate \
--help --list --print --fingerprint --revoke \
--sign --version --verify" -- "$cur" ) )
2011-02-23 21:14:35 +01:00
return 0
esac
esac
;;
describe)
if [[ "$cur" == -* ]]; then
2011-02-23 21:22:18 +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
;;
doc)
case $prev in
--outputdir)
_filedir -d
return 0
;;
--mode)
COMPREPLY=( $( compgen -W "text trac pdf rdoc" -- "$cur" ) )
return 0
;;
--reference)
_puppet_references
return 0
;;
*)
if [[ "$cur" == -* ]]; then
2011-02-23 21:22:18 +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
;;
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:22:18 +01:00
COMPREPLY=( $( compgen -W "--help --version --debug \
--verbose --local --remote --server --bucket" \
-- "$cur" ) )
2011-02-23 21:14:35 +01:00
else
2011-02-23 21:22:18 +01:00
COMPREPLY=( $( compgen -W "backup get restore" \
-- "$cur" ) )
2011-02-23 21:14:35 +01:00
_filedir
fi
return 0
esac
;;
kick)
case $prev in
--class)
return 0
;;
--host)
_known_hosts_real "$cur"
return 0
;;
--tag)
return 0
;;
*)
if [[ "$cur" == -* ]]; then
2011-02-23 21:22:18 +01:00
COMPREPLY=( $( compgen -W "--all --class --debug \
--foreground --help --host --no-fqdn \
--ignoreschedules --tag --test --ping" -- "$cur" ) )
2011-02-23 21:14:35 +01:00
else
_known_hosts_real "$cur"
fi
return 0
esac
;;
master)
case $prev in
--logdest)
_puppet_logdest
return 0
;;
*)
2011-02-23 21:22:18 +01:00
COMPREPLY=( $( compgen -W "--daemonize --no-daemonize \
--debug --help --logdest --verbose --version" \
-- "$cur" ) )
2011-02-23 21:14:35 +01:00
return 0
esac
;;
queue)
case $prev in
--logdest)
_puppet_logdest
return 0
;;
*)
if [[ "$cur" == -* ]]; then
2011-02-23 21:22:18 +01:00
COMPREPLY=( $( compgen -W "--help --version --debug \
--verbose --execute --detailed-exitcodes \
--logdest" -- "$cur" ) )
2011-02-23 21:14:35 +01:00
else
_filedir
fi
return 0
esac
;;
resource|*)
2011-02-23 21:22:18 +01:00
COMPREPLY=( $( compgen -W "--help --version --debug --verbose" \
-- "$cur" ) )
2011-02-23 21:14:35 +01:00
return 0
;;
esac
} &&
complete -F _puppet -o filenames puppetmasterd puppetd puppetca ralsh puppetrun puppetqd filebucket puppetdoc puppet
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh