1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
# 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 --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"
# local variables
local std cmd i prev
local c=1
local cur="`_get_cword`"
local prog="${COMP_WORDS[0]}"
local modpath='oscap'
_split_longopt || prev="${COMP_WORDS[$COMP_CWORD-1]}"
# get module path
while [ $c -lt $COMP_CWORD ]; do
i="${COMP_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
elif [ "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
|