summaryrefslogtreecommitdiff
path: root/misc/crucible-completion.bash
blob: 583e79e9f5f9818d13904ead2881557432e1337c (plain)
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
__crucible_commands="bootstrap dump-image test help ls-tests ls-example-tests run version"

__crucible_bootstrap()
{
   COMPREPLY=($(compgen -W "--help --width --height $($1 ls-tests)" -- ${COMP_WORDS[COMP_CWORD]}))
}

__crucible_dump_image()
{
   COMPREPLY=($(compgen -o filenames -A file -W "--help" -- ${COMP_WORDS[COMP_CWORD]}))
}

__crucible_help()
{
    COMPREPLY=($(compgen -W "$__crucible_commands" -- ${COMP_WORDS[COMP_CWORD]}))
}

__crucible_ls_tests()
{
    COMPREPLY=($(compgen -W "--help" -- ${COMP_WORDS[COMP_CWORD]}))
}

__crucible_run()
{
   local flags="
      --help
      --fork
      --no-fork
      --separate-cleanup-threads
      --no-separate-cleanup-threads
      -I --isolation
      -j --jobs
      --dump
      --no-dump
      --no-cleanup
      --use-spir-v
      --junit-xml
   "

   COMPREPLY=($(compgen -W "$flags $($1 ls-tests)" -- ${COMP_WORDS[COMP_CWORD]}))
}

__crucible()
{
    local i c=1 command
    local crucible_options="--help --version"

    while [ $c -lt $COMP_CWORD ]; do
	i="${COMP_WORDS[c]}"
	case "$i" in
	    -*) ;;
	    *) command="$i"; break ;;
	esac
	c=$((++c))
    done

    if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
	case "${COMP_WORDS[COMP_CWORD]}" in
	    --*=*) COMPREPLY=() ;;
	    -*) COMPREPLY=($(compgen -P "" -W "$crucible_options" -- ${COMP_WORDS[COMP_CWORD]})) ;;
	    *) COMPREPLY=($(compgen -P "" -W "$__crucible_commands $crucible_options" -- ${COMP_WORDS[COMP_CWORD]})) ;;
	esac
	return
    fi

    case "$command" in
	bootstrap) __crucible_bootstrap $1 ;;
	dump-image) __crucible_dump_image $1 ;;
	help) __crucible_help ;;
	ls-tests) __crucible_ls_tests $1 ;;
	run) __crucible_run $1 ;;
	*) COMPREPLY=() ;;
    esac
}

complete -F __crucible crucible ./bin/crucible