|
3 | 3 | # This script expects $1 to be passed and for $1 to be the filesystem location |
4 | 4 | # to a puppet manifest file for which it will run style guide checks against. |
5 | 5 |
|
| 6 | +manifest_path="$1" |
| 7 | +module_dir="$2" |
| 8 | + |
6 | 9 | syntax_errors=0 |
7 | 10 | error_msg=$(mktemp /tmp/error_msg_puppet-lint.XXXXX) |
8 | 11 |
|
9 | | -if [ $2 ]; then |
10 | | - module_path=$(echo $1 | sed -e 's|'$2'||') |
| 12 | +if [ $module_dir ]; then |
| 13 | + manifest_name=$(echo $manifest_path | sed -e 's|'$module_dir'||') |
| 14 | + error_msg_filter="sed -e s|$module_dir||" |
11 | 15 | else |
12 | | - module_path=$1 |
| 16 | + manifest_name="$manifest_path" |
| 17 | + error_msg_filter="sed" |
13 | 18 | fi |
14 | 19 |
|
15 | 20 | # De-lint puppet manifests |
16 | | -echo -e "\x1B[0;36mChecking puppet style guide compliance for $module_path...\x1B[0m" |
17 | | -puppet-lint --fail-on-warnings --with-filename --no-80chars-check $1 2>&1 > $error_msg |
| 21 | +echo -e "$(tput setaf 6)Checking puppet style guide compliance for $manifest_name...$(tput sgr0)" |
| 22 | + |
| 23 | +# If a file named .puppet-lint.rc exists at the base of the repo then use it to |
| 24 | +# enable or disable checks. |
| 25 | +puppet_lint_cmd="puppet-lint --fail-on-warnings --with-filename" |
| 26 | +puppet_lint_rcfile="${2}.puppet-lint.rc" |
| 27 | +if [ -f $puppet_lint_rcfile ]; then |
| 28 | + echo -e "$(tput setaf 6)Applying custom config from .puppet-lint.rc$(tput sgr0)" |
| 29 | + puppet_lint_cmd="$puppet_lint_cmd --config $puppet_lint_rcfile" |
| 30 | +else |
| 31 | + puppet_lint_cmd="$puppet_lint_cmd --no-80chars-check" |
| 32 | +fi |
| 33 | + |
| 34 | +$puppet_lint_cmd $1 2>&1 > $error_msg |
18 | 35 | RC=$? |
19 | 36 | if [ $RC -ne 0 ]; then |
20 | | - echo -en "\x1B[0;31m" |
21 | 37 | syntax_errors=$(expr $syntax_errors + 1) |
22 | | - cat $error_msg |
23 | | - echo -e "Error: styleguide violation in $module_path (see above)\x1B[0m" |
| 38 | + cat $error_msg | $error_msg_filter -e "s/^/$(tput setaf 1)/" -e "s/$/$(tput sgr0)/" |
| 39 | + echo -e "$(tput setaf 1)Error: styleguide violation in $manifest_name (see above)$(tput sgr0)" |
24 | 40 | fi |
25 | 41 | rm -f $error_msg |
26 | 42 |
|
27 | 43 | if [ $syntax_errors -ne 0 ]; then |
28 | | - echo -e "\x1B[0;31mError: $syntax_errors styleguide violation(s) found. Commit will be aborted. |
| 44 | + echo -e "Error: $syntax_errors styleguide violation(s) found. Commit will be aborted. |
29 | 45 | Please follow the puppet style guide outlined at: |
30 | | -http://docs.puppetlabs.com/guides/style_guide.html\x1B[0m" |
| 46 | +http://docs.puppetlabs.com/guides/style_guide.html" | sed -e "s/^/$(tput setaf 1)/" -e "s/$/$(tput sgr0)/" |
31 | 47 | exit 1 |
32 | 48 | fi |
33 | 49 |
|
|
0 commit comments