-
-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Thanks for lot for making this util.
I have been using it to
- format Dockerfiles in my git repo
- check formatting and raise error if formatting differs from existing format
in CI and with a shell util in dev environment that is "agnostic" (a task runner (Makefile here) not linked to vscode for example).
That would be cool if dockerfile-utils format exposes CLI options to match these use case.
A bit like black --check --diff . and black . for another well-known formatted (python here).
It could be dockerfile-utils format --write --recursive . (-w for write and -r for recursively find Dockerfiles, with maybe an optional --regex that defaults to "Dockerfile")
and dockerfile-utils format --check --recursive . to raise errors if the formatting differs.
The current syntax is a bit cumbersome (below).
make format-dockerfiles:
@echo "Formatting Dockerfiles... "
@cd .. && for file in $$( (git ls-files ; git ls-files --others --exclude-standard) | sort -u | grep 'Dockerfile'); do \
tmpFormattedDockerfile=$$(mktemp) ; \
echo -n "Formatting $$file file... " ; \
trap "rm -f $$tmpFormattedDockerfile" EXIT ; \
dockerfile-utils format -t $$file > "$$tmpFormattedDockerfile" && mv "$$tmpFormattedDockerfile" $$file ; \
echo OK && rm -f $$tmpFormattedDockerfile ; \
done; echo Dockerfiles formatted
.PHONY: format-dockerfilescheck-dockerfiles: ## Check coding style
@echo "Checking Dockerfiles... "
@cd .. && for file in $$( (git ls-files ; git ls-files --others --exclude-standard) | sort -u | grep 'Dockerfile'); do \
tmpFormattedDockerfile=$$(mktemp) ; \
trap "rm -f $$tmpFormattedDockerfile" EXIT ; \
echo -n "Checking $$file file... " ; \
dockerfile-utils format -t $$file > "$$tmpFormattedDockerfile" ; \
if ! cmp $$file $$tmpFormattedDockerfile ; then \
echo "Error: $$file is not properly formatted." ; \
exit 1 ; \
fi ; \
echo OK && rm -f $$tmpFormattedDockerfile ; \
done; echo Dockerfiles checked
.PHONY: check-dockerfilesReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels