_codeclimate 2.42 KB
Newer Older
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
#compdef codeclimate

_codeclimate_all_engines() {
  engines_all=(`codeclimate engines:list | tail -n +2 | gawk '{ print $2 }' | gawk -F: '{ print $1 }'`)
}

_codeclimate_installed_engines() {
  _codeclimate_all_engines

  engines_installed=()

  if [ -e .codeclimate.yml ]
  then
    for engine in $engines_all
    do
      if grep -q $engine ".codeclimate.yml"
      then
        engines_installed+=$engine
      fi
    done
  fi
}

_codeclimate_not_installed_engines() {
  _codeclimate_all_engines

  engines_not_installed=()

  if [ -e .codeclimate.yml ]
  then
    for engine in $engines_all
    do
      if ! grep -q $engine ".codeclimate.yml"
      then
        engines_not_installed+=$engine
      fi
    done
  fi
}

local curcontext="$curcontext" state line ret=1
local expl
local -a engines_all engines_installed engines_not_installed

_arguments \
  '1: :->cmds' \
  '*:: :->args' && ret=0

case $state in
  cmds)
    _values "bundle command" \
      "analyze[Analyze all relevant files in the current working directory]" \
      "console[Start an interactive session providing access to the classes within the CLI]" \
      "engines\:disable[Prevents the engine from being used in this project]" \
      "engines\:enable[This engine will be run the next time your project is analyzed]" \
      "engines\:install[Compares the list of engines in your .codeclimate.yml file to those that are currently installed, then installs any missing engines]" \
      "engines\:list[Lists all available engines in the Code Climate Docker Hub]" \
      "engines\:remove[Removes an engine from your .codeclimate.yml file]" \
      "help[Displays a list of commands that can be passed to the Code Climate CLI]" \
      "init[Generates a new .codeclimate.yml file in the current working directory]" \
      "validate-config[Validates the .codeclimate.yml file in the current working directory]" \
      "version[Displays the current version of the Code Climate CLI]"
    ret=0
    ;;
  args)
    case $line[1] in
      engines:enable)
        _codeclimate_not_installed_engines
        _wanted engines_not_installed expl 'not installed engines' compadd -a engines_not_installed ;;
      engines:disable|engines:remove)
        _codeclimate_installed_engines
        _wanted engines_installed expl 'installed engines' compadd -a engines_installed ;;
      analyze)
        _arguments \
          '-f:Output Format:(text json)'
        ret=0
        ;;
    esac
    ;;
esac

return ret