_codeclimate 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #compdef codeclimate
  2. _codeclimate_all_engines() {
  3. engines_all=(`codeclimate engines:list | tail -n +2 | gawk '{ print $2 }' | gawk -F: '{ print $1 }'`)
  4. }
  5. _codeclimate_installed_engines() {
  6. _codeclimate_all_engines
  7. engines_installed=()
  8. if [ -e .codeclimate.yml ]
  9. then
  10. for engine in $engines_all
  11. do
  12. if grep -q $engine ".codeclimate.yml"
  13. then
  14. engines_installed+=$engine
  15. fi
  16. done
  17. fi
  18. }
  19. _codeclimate_not_installed_engines() {
  20. _codeclimate_all_engines
  21. engines_not_installed=()
  22. if [ -e .codeclimate.yml ]
  23. then
  24. for engine in $engines_all
  25. do
  26. if ! grep -q $engine ".codeclimate.yml"
  27. then
  28. engines_not_installed+=$engine
  29. fi
  30. done
  31. fi
  32. }
  33. local curcontext="$curcontext" state line ret=1
  34. local expl
  35. local -a engines_all engines_installed engines_not_installed
  36. _arguments \
  37. '1: :->cmds' \
  38. '*:: :->args' && ret=0
  39. case $state in
  40. cmds)
  41. _values "bundle command" \
  42. "analyze[Analyze all relevant files in the current working directory]" \
  43. "console[Start an interactive session providing access to the classes within the CLI]" \
  44. "engines\:disable[Prevents the engine from being used in this project]" \
  45. "engines\:enable[This engine will be run the next time your project is analyzed]" \
  46. "engines\:install[Compares the list of engines in your .codeclimate.yml file to those that are currently installed, then installs any missing engines]" \
  47. "engines\:list[Lists all available engines in the Code Climate Docker Hub]" \
  48. "engines\:remove[Removes an engine from your .codeclimate.yml file]" \
  49. "help[Displays a list of commands that can be passed to the Code Climate CLI]" \
  50. "init[Generates a new .codeclimate.yml file in the current working directory]" \
  51. "validate-config[Validates the .codeclimate.yml file in the current working directory]" \
  52. "version[Displays the current version of the Code Climate CLI]"
  53. ret=0
  54. ;;
  55. args)
  56. case $line[1] in
  57. engines:enable)
  58. _codeclimate_not_installed_engines
  59. _wanted engines_not_installed expl 'not installed engines' compadd -a engines_not_installed ;;
  60. engines:disable|engines:remove)
  61. _codeclimate_installed_engines
  62. _wanted engines_installed expl 'installed engines' compadd -a engines_installed ;;
  63. analyze)
  64. _arguments \
  65. '-f:Output Format:(text json)'
  66. ret=0
  67. ;;
  68. esac
  69. ;;
  70. esac
  71. return ret