refactor: DRY the runners

This commit is contained in:
Daylin Morgan 2022-09-07 16:11:32 -05:00
parent c1771c1d0f
commit d395d7e2a3
2 changed files with 18 additions and 34 deletions

View file

@ -7,27 +7,19 @@ define \n
endef endef
escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1)))) escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))))
escape_printf = $(subst \,\\,$(subst %,%%,$1)) escape_printf = $(subst \,\\,$(subst %,%%,$1))
create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1))) create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1)))
ifdef DEBUG ifdef DEBUG
define py define _debug_runner
@printf "Python Script:\n" @printf "$(1) Script:\n"
@printf -- "----------------\n" @printf -- "<---------------->\n"
@printf "$(call create_string,$($(1)))\n" @printf "$(call create_string,$(3))\n"
@printf -- "----------------\n" @printf -- "<---------------->\n"
@printf "$(call create_string,$($(1)))" | python3 @printf "$(call create_string,$(3))" | $(2)
endef
define tbash
@printf "Bash Script:\n"
@printf -- "----------------\n"
@printf "$(call create_string,$($(1)))\n"
@printf -- "----------------\n"
@printf "$(call create_string,$($(1)))" | bash
endef endef
py = $(call _debug_runner,Python,python3,$($(1)))
tbash = $(call _debug_runner,Bash,bash,$($(1)))
else else
py = @printf "$(call create_string,$($(1)))" | python3 py = @printf "$(call create_string,$($(1)))" | python3
tbash = @printf "$(call create_string,$($(1)))" | bash tbash = @printf "$(call create_string,$($(1)))" | bash

26
task.mk
View file

@ -1,7 +1,7 @@
# }> [github.com/daylinmorgan/task.mk] <{ # # }> [github.com/daylinmorgan/task.mk] <{ #
# Copyright (c) 2022 Daylin Morgan # Copyright (c) 2022 Daylin Morgan
# MIT License # MIT License
# version: v22.9.7-1-g41c3980-dev # version: v22.9.7-3-gc1771c1-dev
# #
# task.mk should be included at the bottom of your Makefile. # task.mk should be included at the bottom of your Makefile.
# See below for the standard configuration options that should be set prior to including this file. # See below for the standard configuration options that should be set prior to including this file.
@ -70,27 +70,19 @@ define \n
endef endef
escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1)))) escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))))
escape_printf = $(subst \,\\,$(subst %,%%,$1)) escape_printf = $(subst \,\\,$(subst %,%%,$1))
create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1))) create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1)))
ifdef DEBUG ifdef DEBUG
define py define _debug_runner
@printf "Python Script:\n" @printf "$(1) Script:\n"
@printf -- "----------------\n" @printf -- "<---------------->\n"
@printf "$(call create_string,$($(1)))\n" @printf "$(call create_string,$(3))\n"
@printf -- "----------------\n" @printf -- "<---------------->\n"
@printf "$(call create_string,$($(1)))" | python3 @printf "$(call create_string,$(3))" | $(2)
endef
define tbash
@printf "Bash Script:\n"
@printf -- "----------------\n"
@printf "$(call create_string,$($(1)))\n"
@printf -- "----------------\n"
@printf "$(call create_string,$($(1)))" | bash
endef endef
py = $(call _debug_runner,Python,python3,$($(1)))
tbash = $(call _debug_runner,Bash,bash,$($(1)))
else else
py = @printf "$(call create_string,$($(1)))" | python3 py = @printf "$(call create_string,$($(1)))" | python3
tbash = @printf "$(call create_string,$($(1)))" | bash tbash = @printf "$(call create_string,$($(1)))" | bash