Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions scripts/common.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ guard-%:
guard-optional-%:
@:

guard-optional-bool-%:
@if [ "${${*}}" != "true" ] && [ "${${*}}" != "false" ] && [ "${${*}}" != "" ]; then \
echo "Argument '${*}' must be 'true', 'false', or empty"; \
exit 1; \
fi;

# Gracefully use defaults and potentially overwrite them, via https://stackoverflow.com/a/49804748
%: %-default
@ true
Expand Down Expand Up @@ -385,3 +391,27 @@ $(WAIT_FOR_IT): ## installs wait4x utility for WAIT_FOR_IT functionality
@mv /tmp/wait4x/wait4x $@
@rm -rf /tmp/wait4x
@$@ version

# Arguments
# 1 - message to show (e.g. Are you sure?)
# 2 - input to confirm action (e.g. yes)
# 3 - force confirm (e.g. true)
#
# Examples
# $(call confirm_action) -- use with default messages
# $(call confirm_action,Do you want to delete all files?) -- overwrite confirm message
# $(call confirm_action,,,$(CI)) -- ignore in CI (CI := true)
# echo before; $(call confirm_action); echo after -- chain in bash
define confirm_action
CONFIRM_MSG="$(if $(1),$(1),Are you sure?)"; \
CONFIRM_KEY="$(if $(2),$(2),yes)"; \
SKIP_CHECK="$(if $(3),$(3),false)"; \
if [ "$$SKIP_CHECK" != true ]; then \
echo "$$CONFIRM_MSG"; \
read -p "Type '$$CONFIRM_KEY' to confirm: " USER_INPUT; \
if [ "$$USER_INPUT" != "$$CONFIRM_KEY" ]; then \
echo "CONFIRM_KEY does not match. Aborted."; \
exit 1; \
fi; \
fi
endef
Loading