# check for non-parametric options # returns number of params function _oscap_noarg { case "$1" in --definitions|--syschar|--results|--skip-schematron|-f|--force|-q|--quiet|--oval-results) return 0 ;; --version|--help|-V|-h) return 256 ;; # stop cmdline processing *) return 1 ;; esac } function _oscap { # commands for individual modules local -A cmds=() cmds[oscap]="info oval xccdf ds cpe" cmds[oscap:oval]="collect eval analyse validate generate" cmds[oscap:oval:generate]="report" cmds[oscap:xccdf]="eval remediate resolve validate export-oval-variables generate" cmds[oscap:xccdf:generate]="report guide fix custom" cmds[oscap:ds]="sds-validate rds-validate" cmds[oscap:cpe]="check match validate" # command options local -A opts=() opts[oscap]="--version --quiet --help -V -q -h" opts[oscap:oval:validate]="--version --definitions --variables --syschar --results --directives --skip-schematron" opts[oscap:oval:eval]="--datastream-id --oval-id --id --variables --directives --without-syschar --results --report --skip-validation --fetch-remote-resources --local-files --verbose --verbose-log-file" opts[oscap:oval:analyse]="--variables --directives --verbose --verbose-log-file --skip-validation" opts[oscap:oval:collect]="--id --syschar --skip-validation --variables --verbose --verbose-log-file" opts[oscap:oval:generate:report]="-o --output" opts[oscap:xccdf:eval]="--benchmark-id --check-engine-results --cpe --datastream-id --enforce-signature --export-variables --fetch-remote-resources --local-files --oval-results --profile --progress --progress-full --remediate --report --results --results-arf --rule --skip-rule --skip-validation --skip-signature-validation --stig-viewer --tailoring-file --tailoring-id --thin-results --verbose --verbose-log-file --without-syschar --xccdf-id" opts[oscap:xccdf:validate]="--skip-schematron" opts[oscap:xccdf:export-oval-variables]="--datastream-id --xccdf-id --profile --skip-validation --fetch-remote-resources --local-files --benchmark-id --cpe" opts[oscap:xccdf:remediate]="--result-id --skip-validation --fetch-remote-resources --local-files --results --results-arf --report --oval-results --export-variables --cpe --check-engine-results --progress --progress-full" opts[oscap:xccdf:resolve]="-o --output -f --force" opts[oscap:xccdf:generate]="--profile" opts[oscap:xccdf:generate:report]="-o --output --result-id --profile" opts[oscap:xccdf:generate:guide]="-o --output --hide-profile-info --profile --benchmark-id --xccdf-id --tailoring-file --tailoring-id --skip-signature-validation --enforce-signature" opts[oscap:xccdf:generate:fix]="-o --output --profile --result-id --profile --fix-type --xccdf-id --benchmark-id --tailoring-file --tailoring-id --skip-signature-validation --enforce-signature" opts[oscap:xccdf:generate:custom]="-o --output --stylesheet" opts[oscap:info]="--fetch-remote-resources --local-files --profile --profiles --references --list-rules --list-vars" # local variables local cur prev words cword split _init_completion -s || return local cmd i local c=1 local modpath='oscap' # get module path while [ $c -lt $cword ]; do i="${words[c]}" case "$i" in # TODO handle generic switches -*) _oscap_noarg "$i"; c=$((c + $?)) ;; *) modpath="$modpath:$i" ;; esac c=$((c + 1)) done if [ "x${prev:0:1}" == "x-" ] && ! _oscap_noarg "$prev"; then # an option argument local cmd=${modpath##*:} case "$prev" in --results|-o|--output) _filedir 'xml.bz2|xml' ;; --report) _filedir 'html' ;; esac return fi $split && return if [ "x${cur:0:1}" == "x-" ]; then # an option COMPREPLY=( $(compgen -W "${opts[$modpath]}" -- ${cur}) ) elif [ "x${cmds[$modpath]}" != 'x' ]; then # a submodule COMPREPLY=( $(compgen -W "${cmds[$modpath]}" -- ${cur}) ) else # a positional argument case "$modpath" in *) _filedir 'xml.bz2|xml' ;; esac fi } [ "${BASH_VERSINFO[0]}" -ge '4' ] && complete -F _oscap -o filenames oscap