# bash completion for puppet -*- shell-script -*- proc _puppet_logdest { if [[ -z $cur ]] { setglobal COMPREPLY = ''( $( compgen -W 'syslog console /' -- "$cur" ) ) } else { setglobal COMPREPLY = ''( $( compgen -W 'syslog console' -- "$cur" ) ) _filedir } } proc _puppet_digest { setglobal COMPREPLY = ''( $( compgen -W 'MD5 MD2 SHA1 SHA256' -- "$cur" ) ) } proc _puppet_certs { local puppetca="puppet cert" env PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type puppetca &>/dev/null \ && setglobal puppetca = 'puppetca' if [[ "$1" == --all ]] { setglobal cert_list = $[ $puppetca --list --all | sed -e 's/^[+-]\?\s*\(\S\+\)\s\+.*$/\1/] } else { setglobal cert_list = $[ $puppetca --list] } setglobal COMPREPLY = ''( $( compgen -W "$cert_list" -- "$cur" ) ) } proc _puppet_types { setglobal puppet_types = $[ puppet describe --list | sed -e 's/^\(\S\+\).*$/\1/] setglobal COMPREPLY = ''( $( compgen -W "$puppet_types" -- "$cur" ) ) } proc _puppet_references { local puppetdoc="puppet doc" env PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type puppetdoc &>/dev/null \ && setglobal puppetdoc = 'puppetdoc' setglobal puppet_doc_list = $[ $puppetdoc --list | sed -e 's/^\(\S\+\).*$/\1/] setglobal COMPREPLY = ''( $( compgen -W "$puppet_doc_list" -- "$cur" ) ) } proc _puppet_subcmd_opts { # puppet cmd help is somewhat slow, avoid if possible [[ -z $cur || $cur == -* ]] && \ setglobal COMPREPLY = ''( $( compgen -W \ '$( _parse_usage "$1" "help $2" )' -- "$cur" ) ) } proc _puppet { local cur prev words cword _init_completion || return local xspec helpopts subcommand action match $prev { with -h|--help|-V|--version return 0 } match $(words[0]) { with puppetmasterd setglobal subcommand = 'master' with puppetd setglobal subcommand = 'agent' with puppetca setglobal subcommand = 'cert' with ralsh setglobal subcommand = 'resource' with puppetrun setglobal subcommand = 'kick' with puppetqd setglobal subcommand = 'queue' with filebucket setglobal subcommand = 'filebucket' with puppetdoc setglobal subcommand = 'doc' with pi setglobal subcommand = 'describe' with puppet match $(words[1]) { with agent|apply|cert|describe|doc|filebucket|kick|master|parser|queue|resource setglobal subcommand = $(words[1]) with *.pp|*.rb setglobal subcommand = 'apply' with * setglobal COMPREPLY = ''( $( compgen -W 'agent apply cert describe doc filebucket kick master parser queue resource' -- "$cur" ) ) return 0 } } match $subcommand { with agent match $prev { with --certname _known_hosts_real $cur return 0 with --digest _puppet_digest return 0 with --fqdn _known_hosts_real $cur return 0 with -l|--logdest _puppet_logdest return 0 with --masterport setglobal COMPREPLY = ''( $( compgen -W '8140' -- "$cur" ) ) return 0 with -w|--waitforcert setglobal COMPREPLY = ''( $( compgen -W '0 15 30 60 120' -- "$cur" ) ) return 0 with * _puppet_subcmd_opts $1 $subcommand # _parse_usage doesn't grok [-D|--daemonize|--no-daemonize] setglobal COMPREPLY = ''( $( compgen -W '--no-daemonize' -- "$cur" ) ) return 0 } with apply match $prev { with --catalog setglobal COMPREPLY = ''( $( compgen -W '-' -- "$cur" ) ) _filedir json return 0 with --execute return 0 with -l|--logdest _puppet_logdest return 0 with * if [[ "$cur" == -* ]] { _puppet_subcmd_opts $1 $subcommand } else { _filedir } return 0 } with cert match $prev { with --digest _puppet_digest return 0 with * setglobal action = $prev setglobal COMPREPLY = ''( $( compgen -W '--digest --debug --help --verbose --version' \ -- "$cur" ) ) match $action { with fingerprint|list|verify|--fingerprint|--list|--verify setglobal COMPREPLY = ''( $( compgen -W '--all' -- "$cur" ) ) _puppet_certs --all return 0 with generate|--generate _known_hosts_real $cur return 0 with clean|print|revoke|--clean|--print|--revoke _puppet_certs --all return 0 with sign|--sign setglobal COMPREPLY = ''( $( compgen -W '--all' -- "$cur" ) ) _puppet_certs return 0 with * setglobal COMPREPLY = ''( $( compgen -W 'clean fingerprint generate list print revoke sign verify reinventory' -- "$cur" ) ) return 0 } } with describe _puppet_subcmd_opts $1 $subcommand if [[ "$cur" != -* ]] { _puppet_types } return 0 with doc match $prev { with -o|--outputdir _filedir -d return 0 with -m|--mode setglobal COMPREPLY = ''( $( compgen -W 'text trac pdf rdoc' -- "$cur" ) ) return 0 with -r|--reference _puppet_references return 0 with * if [[ "$cur" == -* ]] { _puppet_subcmd_opts $1 $subcommand } else { _filedir } return 0 } with filebucket match $prev { with -s|--server _known_hosts_real $cur return 0 with -b|--bucket _filedir -d return 0 with * if [[ "$cur" == -* ]] { _puppet_subcmd_opts $1 $subcommand } else { setglobal COMPREPLY = ''( $( compgen -W 'backup get restore' \ -- "$cur" ) ) _filedir } return 0 } with kick match $prev { with -c|--class return 0 with --host _known_hosts_real $cur return 0 with -t|--tag return 0 with * if [[ "$cur" == -* ]] { _puppet_subcmd_opts $1 $subcommand } else { _known_hosts_real $cur } return 0 } with master match $prev { with -l|--logdest _puppet_logdest return 0 with * _puppet_subcmd_opts $1 $subcommand # _parse_usage doesn't grok [-D|--daemonize|--no-daemonize] setglobal COMPREPLY = ''( $( compgen -W '--no-daemonize' -- "$cur" ) ) return 0 } with parser setglobal action = $prev match $action { with validate _filedir pp return 0 with * setglobal COMPREPLY = ''( $( compgen -W 'validate' -- "$cur" ) ) return 0 } with queue match $prev { with -l|--logdest _puppet_logdest return 0 with * if [[ "$cur" == -* ]] { _puppet_subcmd_opts $1 $subcommand } else { _filedir } return 0 } with resource|* _puppet_subcmd_opts $1 $subcommand return 0 } } && complete -F _puppet puppetmasterd puppetd puppetca ralsh puppetrun puppetqd filebucket puppetdoc puppet # ex: ts=4 sw=4 et filetype=sh