Repositorio del curso CCOM4030 el semestre B91 del proyecto Paz para la Mujer

uncrustify.sh 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/bash
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing,
  13. # software distributed under the License is distributed on an
  14. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. # KIND, either express or implied. See the License for the
  16. # specific language governing permissions and limitations
  17. # under the License.
  18. #
  19. SCRIPT_PATH=$(dirname $0)
  20. CONFIG="$SCRIPT_PATH/uncrustify.cfg"
  21. EXE="$SCRIPT_PATH/../node_modules/.bin/uncrustify"
  22. function Usage() {
  23. echo "Formats code using uncrustify."
  24. echo "Usage: bin/uncrustify.sh --changed # Runs on changed (staged or not) files"
  25. echo " bin/uncrustify.sh --staged # Runs on staged files"
  26. echo " bin/uncrustify.sh --all # Runs on all source files under the current directory"
  27. echo " bin/uncrustify.sh --check-file file # Returns 1 if the given file requires changes, 0 otherwise."
  28. echo " bin/uncrustify.sh files # Runs on the given files"
  29. exit 1
  30. }
  31. function VerifyEnv() {
  32. if ! which "$EXE" > /dev/null; then
  33. echo "uncrustify binary not found in the cordova-ios repo."
  34. echo "In the repo root, install via npm: npm install"
  35. exit 1
  36. fi
  37. }
  38. function FilterFileList() {
  39. #-name "*.[hm]" | grep -v "JSONKit"
  40. #| grep "\.h\|\.m"
  41. for f in "$@"; do
  42. # Filter out deleted files.
  43. [[ ! -e "$f" ]] && continue
  44. # Filter out non .h & .m files.
  45. [[ "$f" != *.[hm] ]] && continue
  46. # Filter out Third-party sources.
  47. [[ "$f" == *JSONKit* ]] && continue
  48. echo $f
  49. done
  50. }
  51. function FilterAndRun() {
  52. files=$(FilterFileList "$@")
  53. if [[ -z "$files" ]]; then
  54. echo No files to uncrustify.
  55. exit 2
  56. else
  57. echo "$files" | xargs uncrustify -l OC --no-backup -c "$CONFIG"
  58. fi
  59. }
  60. if [[ "$1" = "--changed" ]]; then
  61. VerifyEnv
  62. files=$(git status --porcelain | sed s:...::)
  63. FilterAndRun $files
  64. elif [[ "$1" = "--staged" ]]; then
  65. VerifyEnv
  66. files=$(git diff --cached --name-only)
  67. FilterAndRun $files
  68. elif [[ "$1" = "--all" ]]; then
  69. VerifyEnv
  70. files=$(find .)
  71. FilterAndRun $files
  72. elif [[ "$1" = "--check-file" ]]; then
  73. "$EXE" -q -l OC -c "$CONFIG" -f "$2" | cmp --quiet - "$2"
  74. elif [[ "$1" = "--filter" ]]; then
  75. FilterFileList "$@"
  76. elif [[ "$1" = -* ]]; then
  77. Usage
  78. else
  79. VerifyEnv
  80. FilterAndRun "$@"
  81. fi