forked from Clinical-Genomics/MIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmip-check
executable file
·77 lines (64 loc) · 1.97 KB
/
mip-check
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
version=0.02
usage="$(basename "$0") [-h] [-v] [-s n] FILES[OPTIONAL]
Program for tidying perl scripts and running perl critic. Also checks that modified files has had their version updated.
Default input files are new and modified files.
Version: $version
where:
-h show this help text
-s set the perl critic severity (default: 1)
-v show version number"
## Set default severity for perl critic
critic_severity=1
while getopts ':hs:v' option; do
case "$option" in
h) echo "$usage"
exit
;;
s) critic_severity=$OPTARG
;;
:) printf "missing argument for -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
v) echo "Version: $version"
exit
;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
## Get infiles from command line
infiles=( "$@" )
## Otherwise, get infiles from git
if [ ${#infiles[@]} -lt 1 ] ; then
infiles=$(git status --short | perl -nae 'print $F[1] . q{ }')
fi
## Get current dir
mip_dir="$(dirname "$(readlink -f "$0")")"
for infile in ${infiles[@]}
do
## Only operate on perl files
if ! [[ $infile =~ .*\.(t|pm|pl|test)$ ]] ; then
echo "[SKIPPING]: $infile"
continue
fi
echo ""
echo "[INFILE]: $infile"
## Check if file has been modified
if [ "$(git status --short $infile | perl -nae 'print $F[0]')" == "M" ] ; then
## Check that the "our $VERSION" line has been updated
version_update=$(git diff $infile | perl -nae 'if ($_ =~ /\bour\s\$VERSION\b/xms) {print q{OK}; exit 0}')
if [ "$version_update" != "OK" ] ; then
echo "[UPDATE VERSION]: $infile"
fi
fi
## Run perltidy
perltidy --maximum-line-length=90 --iterations=2 -b -bext='/' $infile
## Run perlcritic
echo "[PERL CRITIC]"
perlcritic \-${critic_severity} \-p ${mip_dir}/.perlcriticrc_mip $infile
done