Commit 73be18b0 authored by sergeizharko's avatar sergeizharko
Browse files

Add run-clang-format command to run

parent 28265f89
......@@ -8,8 +8,26 @@
#
######
#########################
# Envintonment settings #
#########################
# paths to clang-format and git-clang-format binaries
# NOTE: HowTo use clang-format at CBM: https://redmine.cbm.gsi.de/projects/cbmroot/wiki/Clang-format
export GIT_CLANG_FORMAT_BIN=/home/sergei/research/CBM/clang-format-11.0.0_Linux/bin/git-clang-format
export CLANG_FORMAT_BIN=/home/sergei/research/CBM/clang-format-11.0.0_Linux/bin/clang-format
#####################
# Utility variables #
#####################
REGEXP_ISINTEGER='^[0-9]+$'
#########################################
# Commands (bash functions) definitions #
#########################################
# Command to rebuild cbmroot from any place of code
rebuild-cbm() {
# Variables
......@@ -17,7 +35,7 @@ rebuild-cbm() {
# Check input parameters
while [[ $# > 0 ]]; do
echo ${1}
#echo ${1}
case ${1} in
-j )
if [[ ${2} =~ $REGEXP_ISINTEGER ]]; then
......@@ -42,3 +60,74 @@ rebuild-cbm() {
echo "CbmRoot was not compiled, some errors occured"
fi
}
# Command to run clang-format
run-clang-format() {
# Check if the envinronment is correct
local RES=0
if [[ ! -f $GIT_CLANG_FORMAT_BIN ]]; then
echo "ERROR: The GIT_CLANG_FORMAT_BIN variable contains path to non-existing file: $GIT_CLANG_FORMAT_BIN."
echo " Please, put the full path to the git-clang-format binary in this variable."
echo " For further instructions see: https://redmine.cbm.gsi.de/projects/cbmroot/wiki/Clang-format"
RES=1
fi
if [[ ! -f $CLANG_FORMAT_BIN ]]; then
echo "ERROR: The CLANG_FORMAT_BIN variable contains path to non-existing file: $CLANG_FORMAT_BIN."
echo " Please, put the full path to the clang-format binary in this variable."
echo " For further instructions see: https://redmine.cbm.gsi.de/projects/cbmroot/wiki/Clang-format"
RES=1
fi
if [[ $RES -eq 1 ]]; then
return -1
fi
local OPT=""
# Check input parameters
while [[ $# > 0 ]]; do
#echo ${1}
case ${1} in
-h | --help )
echo "Description:"
echo " The command calls the \$VMCWORKDIR/scripts/check-apply-format-changes.sh script"
echo " to apply required code formatting modifications. For further clang-format usage instructions"
echo " please see https://redmine.cbm.gsi.de/projects/cbmroot/wiki/Clang-format"
echo "Usage:"
echo " run-clang-format [option]"
echo "Options:"
echo " -h | --help Show this instructions"
echo " -a | --apply | apply Run \$VMCWORKDIR/scripts/check-apply-format-changes.sh apply"
echo " -c | --check | check Run \$VMCWORKDIR/scripts/check-apply-format-changes.sh check"
return 0
;;
check | --check | -c)
OPT=check
break
;;
apply | --apply | -a)
OPT=apply
break
;;
* )
echo "Wrong option was selected! Please, call \"run-clang-format -h\" to see intstructions"
return -1
;;
esac
shift
done
# Execute a script
pushd .
cd $VMCWORKDIR
./scripts/check-apply-format-changes.sh $OPT
RES=$?
popd
if [[ $RES -eq 0 ]]; then
echo "Done!"
else
echo "Some errors occured while running clang-format"
fi
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment