Skip to content

Commit 208c7e8

Browse files
authored
Extend common makefile (#1196)
1 parent c735594 commit 208c7e8

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

scripts/common.Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ guard-%:
285285
guard-optional-%:
286286
@:
287287
288+
guard-optional-bool-%:
289+
@if [ "${${*}}" != "true" ] && [ "${${*}}" != "false" ] && [ "${${*}}" != "" ]; then \
290+
echo "Argument '${*}' must be 'true', 'false', or empty"; \
291+
exit 1; \
292+
fi;
293+
288294
# Gracefully use defaults and potentially overwrite them, via https://stackoverflow.com/a/49804748
289295
%: %-default
290296
@ true
@@ -385,3 +391,27 @@ $(WAIT_FOR_IT): ## installs wait4x utility for WAIT_FOR_IT functionality
385391
@mv /tmp/wait4x/wait4x $@
386392
@rm -rf /tmp/wait4x
387393
@$@ version
394+
395+
# Arguments
396+
# 1 - message to show (e.g. Are you sure?)
397+
# 2 - input to confirm action (e.g. yes)
398+
# 3 - force confirm (e.g. true)
399+
#
400+
# Examples
401+
# $(call confirm_action) -- use with default messages
402+
# $(call confirm_action,Do you want to delete all files?) -- overwrite confirm message
403+
# $(call confirm_action,,,$(CI)) -- ignore in CI (CI := true)
404+
# echo before; $(call confirm_action); echo after -- chain in bash
405+
define confirm_action
406+
CONFIRM_MSG="$(if $(1),$(1),Are you sure?)"; \
407+
CONFIRM_KEY="$(if $(2),$(2),yes)"; \
408+
SKIP_CHECK="$(if $(3),$(3),false)"; \
409+
if [ "$$SKIP_CHECK" != true ]; then \
410+
echo "$$CONFIRM_MSG"; \
411+
read -p "Type '$$CONFIRM_KEY' to confirm: " USER_INPUT; \
412+
if [ "$$USER_INPUT" != "$$CONFIRM_KEY" ]; then \
413+
echo "CONFIRM_KEY does not match. Aborted."; \
414+
exit 1; \
415+
fi; \
416+
fi
417+
endef

0 commit comments

Comments
 (0)