Skip to content

Commit 3983c0f

Browse files
committed
Add puppet validation argument passing
1 parent 4bc2078 commit 3983c0f

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ Provides the following hooks:
4141
3. Run `pre-commit install` to add pre-commit git hooks. You can also run
4242
`pre-commit run --all-files`, which is useful as part of your tests.
4343

44-
Note that currently it's only possible to use the Puppet 3 parser for
45-
validation. The Puppet 4 parser has many changes, and it's planned to have a
46-
separate branch for Puppet 4 hooks in the future.
44+
To use the future parser with validation, just pass it as an argument
45+
to the `puppet-validate` hook:
46+
47+
- id: puppet-validate
48+
args: [--parser=future]
49+
50+
This option will only work for Puppet 3. For Puppet 4, just use a
51+
updated version of `puppet` to run these hooks and remove the argument.
52+
53+
Any other arguments to `puppet-validate` will be fed directly to
54+
`puppet parser validate`, as long as they are in the format `--arg=value`.

bin/puppet-validate

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
#!/usr/bin/env bash
22
set -eu
33

4+
options=""
5+
opts_regex="^--.+=.+$"
6+
47
status=0
5-
for path in "$@"; do
6-
output=$(puppet parser validate -- "$path" 2>&1) || {
7-
echo -e "\033[31m\033[1m$path: failed Puppet validation\033[0m"
8-
echo "$output"
9-
status=1
10-
}
8+
for arg in "$@"; do
9+
# Check if the argument is a puppet validation option or a file
10+
# The extra arguments always come first, so this will work fine
11+
if [[ "$arg" =~ $opts_regex ]]; then
12+
options="$options $arg"
13+
else
14+
output=$(puppet parser validate $options -- "$arg" 2>&1) || {
15+
echo -e "\033[31m\033[1m$arg: failed Puppet validation\033[0m"
16+
echo "$output"
17+
status=1
18+
}
19+
fi
1120
done
1221

1322
exit "$status"

0 commit comments

Comments
 (0)