dbeam | 54c48b3 | 2016-12-22 21:12:04 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | if [[ -z "${@}" ]]; then |
| 7 | echo >&2 "Usage: `basename $0` <paths_to_clang_format...>"; |
| 8 | exit 1; |
| 9 | fi |
| 10 | |
| 11 | which clang-format >/dev/null 2>&1; |
| 12 | if [[ $? -ne 0 ]]; then |
| 13 | echo >&2 "Sorry, but you need \`clang-format\` on your \$PATH to run this script"; |
| 14 | exit 1; |
| 15 | fi |
| 16 | |
| 17 | for arg in "${@}"; do |
| 18 | dir=`readlink -f "${arg}"` |
| 19 | while dir=`dirname ${dir}`; do |
| 20 | if [[ -f "${dir}/.clang-format" ]]; then |
| 21 | echo "Using style from: ${dir}/.clang-format"; |
| 22 | break; |
| 23 | elif [[ "${dir}" == "/" ]]; then |
| 24 | echo >&2 "No .clang-format file found. Make one at or above ${arg}"; |
| 25 | exit 1; |
| 26 | fi |
| 27 | done |
| 28 | done |
| 29 | |
| 30 | find "${@}" -type f -iname '*.js' | xargs clang-format -i -style=file; |