Debian Codegraph @

dist/bash_completion.d/oscap

raw
1
2 # check for non-parametric options
3 # returns number of params
4 function _oscap_noarg {
5 case "$1" in
6 --definitions|--syschar|--results|--skip-schematron|-f|--force|-q|--quiet|--oval-results) return 0 ;;
7 --version|--help|-V|-h) return 256 ;; # stop cmdline processing
8 *) return 1 ;;
9 esac
10 }
11
12 function _oscap {
13
14 # commands for individual modules
15 local -A cmds=()
16 cmds[oscap]="info oval xccdf ds cpe"
17 cmds[oscap:oval]="collect eval analyse validate generate"
18 cmds[oscap:oval:generate]="report"
19 cmds[oscap:xccdf]="eval remediate resolve validate export-oval-variables generate"
20 cmds[oscap:xccdf:generate]="report guide fix custom"
21 cmds[oscap:ds]="sds-validate rds-validate"
22 cmds[oscap:cpe]="check match validate"
23
24 # command options
25 local -A opts=()
26 opts[oscap]="--version --quiet --help -V -q -h"
27 opts[oscap:oval:validate]="--version --definitions --variables --syschar --results --directives --skip-schematron"
28 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"
29 opts[oscap:oval:analyse]="--variables --directives --verbose --verbose-log-file --skip-validation"
30 opts[oscap:oval:collect]="--id --syschar --skip-validation --variables --verbose --verbose-log-file"
31 opts[oscap:oval:generate:report]="-o --output"
32 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"
33 opts[oscap:xccdf:validate]="--skip-schematron"
34 opts[oscap:xccdf:export-oval-variables]="--datastream-id --xccdf-id --profile --skip-validation --fetch-remote-resources --local-files --benchmark-id --cpe"
35 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"
36 opts[oscap:xccdf:resolve]="-o --output -f --force"
37 opts[oscap:xccdf:generate]="--profile"
38 opts[oscap:xccdf:generate:report]="-o --output --result-id --profile"
39 opts[oscap:xccdf:generate:guide]="-o --output --hide-profile-info --profile --benchmark-id --xccdf-id --tailoring-file --tailoring-id --skip-signature-validation --enforce-signature"
40 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"
41 opts[oscap:xccdf:generate:custom]="-o --output --stylesheet"
42 opts[oscap:info]="--fetch-remote-resources --local-files --profile --profiles --references --list-rules --list-vars"
43
44 # local variables
45 local cur prev words cword split
46 _init_completion -s || return
47 local cmd i
48 local c=1
49 local modpath='oscap'
50
51 # get module path
52 while [ $c -lt $cword ]; do
53 i="${words[c]}"
54 case "$i" in
55 # TODO handle generic switches
56 -*) _oscap_noarg "$i"; c=$((c + $?)) ;;
57 *) modpath="$modpath:$i" ;;
58 esac
59 c=$((c + 1))
60 done
61
62 if [ "x${prev:0:1}" == "x-" ] && ! _oscap_noarg "$prev"; then
63 # an option argument
64
65 local cmd=${modpath##*:}
66
67 case "$prev" in
68 --results|-o|--output) _filedir 'xml.bz2|xml' ;;
69 --report) _filedir 'html' ;;
70 esac
71
72 return
73 fi
74
75 $split && return
76
77 if [ "x${cur:0:1}" == "x-" ]; then
78 # an option
79 COMPREPLY=( $(compgen -W "${opts[$modpath]}" -- ${cur}) )
80 elif [ "x${cmds[$modpath]}" != 'x' ]; then
81 # a submodule
82 COMPREPLY=( $(compgen -W "${cmds[$modpath]}" -- ${cur}) )
83 else
84 # a positional argument
85
86 case "$modpath" in
87 *) _filedir 'xml.bz2|xml' ;;
88 esac
89
90 fi
91
92 }
93
94 [ "${BASH_VERSINFO[0]}" -ge '4' ] && complete -F _oscap -o filenames oscap
95