Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save acumenix/8252be82914299365371f2a27041236f to your computer and use it in GitHub Desktop.
Save acumenix/8252be82914299365371f2a27041236f to your computer and use it in GitHub Desktop.
bundle exec bin/inspec env zsh
function _inspec() {
local curcontext="$curcontext" state line
typeset -A opt_args
local -a _top_level_commands _msccm_commands _scap_commands _secrets_chef_vault_commands _compliance_commands _init_commands _supermarket_commands
_top_level_commands=(
'help:Describe available commands or one specific command'
'json:read all tests in PATH and generate a JSON summary'
'check:verify all tests at the specified PATH'
'archive:archive a profile to tar.gz (default) or zip'
'exec:run all test files at the specified PATH.'
'detect:detect the target OS'
'shell:open an interactive debugging shell'
'env:Output shell-appropriate completion configuration'
'version:prints the version of this tool'
'msccm:Microsoft Systems Center Configuration Manager commands'
'scap:SCAP commands'
'secrets-chef-vault:Vault commands'
'compliance:Chef Compliance commands'
'init:Scaffolds a new project'
'supermarket:Supermarket commands'
)
_msccm_commands=(
'help:Describe subcommands or one specific subcommand'
'coverage:Coverage of a MSCCM profile support in InSpec'
'convert:Convert a MSCCM profile to InSpec'
'info:Displays information about a MSCCM file'
)
_scap_commands=(
'help:Describe subcommands or one specific subcommand'
'coverage:Coverage of a SCAP profile's supported resources'
'convert:Convert a SCAP profile to native InSpec'
)
_secrets_chef_vault_commands=(
'help:Describe subcommands or one specific subcommand'
'login:list all available profiles in Chef Supermarket'
)
_compliance_commands=(
'help:Describe subcommands or one specific subcommand'
'login:Log in to a Chef Compliance SERVER'
'profiles:list all available profiles in Chef Compliance'
'exec:executes a Chef Compliance profile'
'upload:uploads a local profile to Chef Compliance'
'version:displays the version of the Chef Compliance server'
'logout:user logout from Chef Compliance'
)
_init_commands=(
'help:Describe subcommands or one specific subcommand'
'profile:Create a new profile'
)
_supermarket_commands=(
'help:Describe subcommands or one specific subcommand'
'profiles:list all available profiles in Chef Supermarket'
'exec:execute a Supermarket profile'
'info:display Supermarket profile details'
)
_arguments '1:::->toplevel' && return 0
_arguments '2:::->subcommand' && return 0
_arguments '3:::->subsubcommand' && return 0
#
# Are you thinking? "Jeez, whoever wrote this really doesn't get
# zsh's completion system?" If so, you are correct. However, I
# have goodnews! Pull requests are accepted!
#
case $state in
toplevel)
_describe -t commands "InSpec subcommands" _top_level_commands
;;
subcommand)
case "$words[2]" in
archive|check|exec|json)
_alternative 'files:filenames:_files'
;;
help)
_describe -t commands "InSpec subcommands" _top_level_commands
;;
msccm)
_describe -t supermarket_commands "InSpec msccm subcommands" _msccm_commands
;;
scap)
_describe -t supermarket_commands "InSpec scap subcommands" _scap_commands
;;
secrets_chef_vault)
_describe -t supermarket_commands "InSpec secrets_chef_vault subcommands" _secrets_chef_vault_commands
;;
compliance)
_describe -t supermarket_commands "InSpec compliance subcommands" _compliance_commands
;;
init)
_describe -t supermarket_commands "InSpec init subcommands" _init_commands
;;
supermarket)
_describe -t supermarket_commands "InSpec supermarket subcommands" _supermarket_commands
;;
esac
;;
subsubcommand)
case "$words[2]-$words[3]" in
compliance-upload)
_alternative 'files:filenames:_files'
;;
msccm-help)
_describe -t supermarket_commands "InSpec msccm subcommands" _msccm_commands
;;
scap-help)
_describe -t supermarket_commands "InSpec scap subcommands" _scap_commands
;;
secrets_chef_vault-help)
_describe -t supermarket_commands "InSpec secrets_chef_vault subcommands" _secrets_chef_vault_commands
;;
compliance-help)
_describe -t supermarket_commands "InSpec compliance subcommands" _compliance_commands
;;
init-help)
_describe -t supermarket_commands "InSpec init subcommands" _init_commands
;;
supermarket-help)
_describe -t supermarket_commands "InSpec supermarket subcommands" _supermarket_commands
;;
esac
esac
}
compdef _inspec inspec
# To use this, eval it in your shell
#
# eval "$(inspec env zsh)"
#
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment