Skip to content

Commit 7663742

Browse files
committed
feat: allow disabling pushd with --no-cd
1 parent b8e2684 commit 7663742

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ repos:
3838
hooks:
3939
- id: packer_fmt
4040
- id: packer_validate
41+
args: [--no-cd] # Optionally disable changing working directory
4142
```
4243
4344
## Contributing ##

hooks/packer_validate.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ set -o pipefail
77
function packer_validate() {
88
local exit_code=0
99

10-
packer init . > /dev/null
10+
packer init $1 > /dev/null
1111

1212
# Allow us to get output if the validation fails
1313
set +o errexit
14-
validate_output=$(packer validate "${ARGS[@]}" . 2>&1)
14+
validate_output=$(packer validate "${ARGS[@]}" $1 2>&1)
1515
exit_code=$?
1616
set -o errexit
1717

@@ -42,8 +42,12 @@ pids=()
4242
for path in "${UNIQUE_PATHS[@]}"; do
4343
# Check each path in parallel
4444
{
45-
pushd "$path" > /dev/null
46-
packer_validate
45+
if [[ $NO_CD -eq 1 ]]; then
46+
packer_validate $path
47+
else
48+
pushd "$path" > /dev/null
49+
packer_validate .
50+
fi
4751
} &
4852
pids+=("$!")
4953
done

lib/util.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ set -o pipefail
99
# Globals:
1010
# ARGS
1111
# FILES
12+
# NO_CD
1213
#######################################
1314
function util::parse_cmdline() {
1415
# Global variable arrays
1516
ARGS=()
1617
FILES=()
18+
export NO_CD=0
1719

1820
while (("$#")); do
1921
case "$1" in
22+
--no-cd)
23+
NO_CD=1
24+
shift
25+
;;
2026
-*)
2127
if [ -f "$1" ]; then
2228
FILES+=("$1")

0 commit comments

Comments
 (0)