代码拉取完成,页面将自动刷新
#!/bin/bash
function usage() {
echo "Usage: $0 test|reformat"
}
if [ $# -eq 0 ]
then
usage
exit 0
fi
if [ -z "$CLANG_FORMAT" ]
then
CLANG_FORMAT=clang-format
echo "No CLANG_FORMAT set. Using $CLANG_FORMAT"
fi
if ! type "$CLANG_FORMAT" &> /dev/null
then
echo "The command \"$CLANG_FORMAT\" was not found"
exit 1
fi
SOURCE_FILES=$(git ls-files src/)
if [ "$1" == "reformat" ]
then
echo "Reformatting source files"
# shellcheck disable=2086
echo $CLANG_FORMAT -style=file -i $SOURCE_FILES
# shellcheck disable=2086
$CLANG_FORMAT -style=file -i $SOURCE_FILES
exit 0
elif [ "$1" == "test" ]
then
# shellcheck disable=2086
RESULT=$($CLANG_FORMAT -style=file -output-replacements-xml $SOURCE_FILES | grep -c '<replacement ')
if [ "$RESULT" -eq 0 ]
then
echo "code is formatted correctly :)"
exit 0
else
echo "code is not formatted correctly! :("
echo "Suggested change:"
cp -r src clang_format_src
$CLANG_FORMAT -style=file -i clang_format_src/*.c clang_format_src/*.h
diff -ur src clang_format_src
rm -r clang_format_src
echo "Run '$0 reformat' to fix formatting"
exit 1
fi
else
echo "invalid command: $1"
usage
exit 1
fi
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。