Skip to content

Commit

Permalink
puppet: Parse most subcommand options from "help subcommand" output
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Jun 2, 2014
1 parent f94d1a6 commit 00a80a2
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions completions/puppet
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ _puppet_references()
COMPREPLY+=( $( compgen -W "$puppet_doc_list" -- "$cur" ) )
}

_puppet_subcmd_opts()
{
# puppet cmd help is somewhat slow, avoid if possible
[[ -z $cur || $cur == -* ]] && \
COMPREPLY+=( $( compgen -W \
'$( _parse_usage "$1" "help $2" )' -- "$cur" ) )
}

_puppet()
{
local cur prev words cword
Expand Down Expand Up @@ -130,10 +138,9 @@ _puppet()
return 0
;;
*)
COMPREPLY=( $( compgen -W '--certname --daemonize --no-daemonize
--debug --detailed-exitcodes --digest --disable --enable --fingerprint
--help --logdest --masterport --no-client --noop --onetime --test
--verbose --version --waitforcert' -- "$cur" ) )
_puppet_subcmd_opts "$1" $subcommand
# _parse_usage doesn't grok [-D|--daemonize|--no-daemonize]
COMPREPLY+=( $( compgen -W '--no-daemonize' -- "$cur" ) )
return 0
esac
;;
Expand All @@ -153,9 +160,7 @@ _puppet()
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--debug --detailed-exitcodes --help
--loadclasses --logdest --noop --execute --test --verbose
--catalog --write-catalog-summary' -- "$cur" ) )
_puppet_subcmd_opts "$1" $subcommand
else
_filedir
fi
Expand Down Expand Up @@ -199,7 +204,7 @@ _puppet()
esac
;;
describe)
COMPREPLY=( $( compgen -W '--help --providers --list --meta --short' -- "$cur" ) )
_puppet_subcmd_opts "$1" $subcommand
if [[ "$cur" != -* ]]; then
_puppet_types
fi
Expand All @@ -221,8 +226,7 @@ _puppet()
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--all --help --outputdir
--mode --reference --charset --list' -- "$cur" ) )
_puppet_subcmd_opts "$1" $subcommand
else
_filedir
fi
Expand All @@ -241,9 +245,7 @@ _puppet()
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--help --version --debug
--verbose --local --remote --server --bucket' \
-- "$cur" ) )
_puppet_subcmd_opts "$1" $subcommand
else
COMPREPLY=( $( compgen -W 'backup get restore' \
-- "$cur" ) )
Expand All @@ -266,9 +268,7 @@ _puppet()
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--all --class --debug
--foreground --help --host --no-fqdn
--ignoreschedules --tag --test --ping' -- "$cur" ) )
_puppet_subcmd_opts "$1" $subcommand
else
_known_hosts_real "$cur"
fi
Expand All @@ -282,9 +282,9 @@ _puppet()
return 0
;;
*)
COMPREPLY=( $( compgen -W '--daemonize --no-daemonize
--debug --help --logdest --verbose --version' \
-- "$cur" ) )
_puppet_subcmd_opts "$1" $subcommand
# _parse_usage doesn't grok [-D|--daemonize|--no-daemonize]
COMPREPLY+=( $( compgen -W '--no-daemonize' -- "$cur" ) )
return 0
esac
;;
Expand All @@ -308,18 +308,15 @@ _puppet()
;;
*)
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--help --version --debug
--verbose --execute --detailed-exitcodes
--logdest' -- "$cur" ) )
_puppet_subcmd_opts "$1" $subcommand
else
_filedir
fi
return 0
esac
;;
resource|*)
COMPREPLY=( $( compgen -W '--help --version --debug --verbose' \
-- "$cur" ) )
_puppet_subcmd_opts "$1" $subcommand
return 0
;;
esac
Expand Down

0 comments on commit 00a80a2

Please sign in to comment.