refactor: make print-vars parsing based to prevent exporting

This commit is contained in:
Daylin Morgan 2023-01-20 12:19:35 -06:00
parent 920c7c2cc8
commit 365e0e1353
4 changed files with 17 additions and 24 deletions

View file

@ -69,7 +69,7 @@ info: ## demonstrate usage of tprint
task.mk: $(TEMPLATES) generate.py
./generate.py $(VERSION) > task.mk
-include .task.mk .task.cfg.mk
-include .task.cfg.mk .task.mk
.task.mk: $(TEMPLATES) generate.py
$(call msg,re-jinjaing the local .task.mk)
@./generate.py $(VERSION) > .task.mk || (echo "generator failed!!" && rm .task.mk)

View file

@ -8,10 +8,10 @@ h help: ## show this help
_help: export SHOW_HIDDEN=true
_help: help
ifdef PRINT_VARS
$(foreach v,$(PRINT_VARS),$(eval export $(v)))
TASKMK_VARS=$(subst $(eval ) ,<|>,$(foreach v,$(PRINT_VARS),$(v)=$($(v))))
.PHONY: vars v
vars v:
$(call py,vars_py,$(PRINT_VARS))
v vars:
$(call py,vars_py,$(TASKMK_VARS))
endif
### |> -ws --hidden
### task.mk builtins: |> -d --hidden

View file

@ -10,15 +10,10 @@ from utils import Ansi
# -###
##- '$(utils_py)' -##
ansi = Ansi(target="stdout")
vars = "$2".split()
length = max((len(v) for v in vars))
print(f"{ansi.header}vars{ansi.end}:\n")
for v in vars:
print(f" {ansi.params}{v:<{length}}{ansi.end} = {os.getenv(v)}")
print()
###- $2 is a list of variables set by task.mk delimited with '<|>' -###
task_vars = tuple(v.split('=') for v in "$2".split('<|>'))
length = max((len(v[0]) for v in task_vars))
rows = (f" {ansi.params}{v[0]:<{length}}{ansi.end} = {v[1]}" for v in task_vars)
print('\n'.join((f"{ansi.header}vars{ansi.end}:\n", *rows,'')))
#% endblock %#

18
task.mk
View file

@ -1,7 +1,7 @@
# }> [github.com/daylinmorgan/task.mk] <{ #
# Copyright (c) 2022 Daylin Morgan
# MIT License
# version: v22.9.28-13-gfd96a45dev
# version: v22.9.28-16-g920c7c2dev
#
# task.mk should be included at the bottom of your Makefile with `-include .task.mk`
# See below for the standard configuration options that should be set prior to including this file.
@ -30,10 +30,10 @@ h help: ## show this help
_help: export SHOW_HIDDEN=true
_help: help
ifdef PRINT_VARS
$(foreach v,$(PRINT_VARS),$(eval export $(v)))
TASKMK_VARS=$(subst $(eval ) ,<|>,$(foreach v,$(PRINT_VARS),$(v)=$($(v))))
.PHONY: vars v
vars v:
$(call py,vars_py,$(PRINT_VARS))
v vars:
$(call py,vars_py,$(TASKMK_VARS))
endif
### |> -ws --hidden
### task.mk builtins: |> -d --hidden
@ -286,12 +286,10 @@ define vars_py
import os
$(utils_py)
ansi = Ansi(target="stdout")
vars = "$2".split()
length = max((len(v) for v in vars))
print(f"{ansi.header}vars{ansi.end}:\n")
for v in vars:
print(f" {ansi.params}{v:<{length}}{ansi.end} = {os.getenv(v)}")
print()
task_vars = tuple(v.split('=') for v in "$2".split('<|>'))
length = max((len(v[0]) for v in task_vars))
rows = (f" {ansi.params}{v[0]:<{length}}{ansi.end} = {v[1]}" for v in task_vars)
print('\n'.join((f"{ansi.header}vars{ansi.end}:\n", *rows,'')))
endef
define confirm_py
import sys