mirror of
https://github.com/daylinmorgan/task.mk.git
synced 2024-12-22 01:50:44 -06:00
fix: allow shorter syntax in usage/epilog
This commit is contained in:
parent
63eb8ac754
commit
b75a3c2c98
5 changed files with 151 additions and 180 deletions
2
Makefile
2
Makefile
|
@ -68,7 +68,7 @@ task.mk: $(TEMPLATES) generate.py
|
|||
./generate.py $(VERSION) > task.mk
|
||||
|
||||
define USAGE
|
||||
{a.$(HEADER_STYLE)}usage:{a.end}\n make <recipe>\n
|
||||
{a.style('usage','header')}:\n make <recipe>\n
|
||||
Turn your {a.style('`Makefile`','b_magenta')} into
|
||||
the {a.italic}{a.underline}task runner{a.end} you always needed.
|
||||
See the example output below.\n
|
||||
|
|
|
@ -1,126 +1,124 @@
|
|||
{"version": 2, "width": 60, "height": 20, "timestamp": 1663712193, "env": {"SHELL": "/usr/bin/zsh", "TERM": "xterm-256color"}}
|
||||
[0.008386, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[0.008986, "o", "bash >> "]
|
||||
[0.009151, "o", "m"]
|
||||
[0.189701, "o", "a"]
|
||||
[0.280162, "o", "k"]
|
||||
[0.37038, "o", "e"]
|
||||
[0.460683, "o", " -"]
|
||||
[0.551001, "o", "f"]
|
||||
[0.641267, "o", " "]
|
||||
[0.731609, "o", "e"]
|
||||
[0.821777, "o", "m"]
|
||||
[0.912103, "o", "be"]
|
||||
[1.092658, "o", "d"]
|
||||
[1.182705, "o", "d"]
|
||||
[1.273152, "o", "e"]
|
||||
[1.363457, "o", "d"]
|
||||
[1.453758, "o", "/e"]
|
||||
[1.544059, "o", "m"]
|
||||
[1.634282, "o", "b"]
|
||||
[1.724452, "o", "e"]
|
||||
[1.814601, "o", "d"]
|
||||
[1.995155, "o", "de"]
|
||||
[2.085437, "o", "d"]
|
||||
[2.175546, "o", "."]
|
||||
[2.265856, "o", "m"]
|
||||
[2.356192, "o", "k"]
|
||||
[2.446468, "o", " h"]
|
||||
[2.536781, "o", "e"]
|
||||
[2.627101, "o", "l"]
|
||||
[2.717423, "o", "p"]
|
||||
[2.897934, "o", "\r\n"]
|
||||
[3.931131, "o", "\u001b[1;36musage:\u001b[0m\r\n\tmake <recipe>\r\n\t\r\n\texamples of embedded scripts in `\u001b[35mMakefile\u001b[0m`\r\n\r\n \u001b[1;31m examples of task.mk features \u001b[0m\r\n\u001b[38m ─────────────────────────────────────────────────────\u001b[0m\r\n\u001b[1;33m list-%\u001b[0m │ \u001b[2muse pathlib.Path to list files\u001b[0m\r\n \u001b[2mname the directory in rule (make list-src)\u001b[0m\r\n\u001b[1;33m embedded-bash\u001b[0m │ \u001b[2mbash script with pipes and make input\u001b[0m\r\n\u001b[1;33m h, help\u001b[0m │ \u001b[2mshow this help\u001b[0m\r\n\r\n"]
|
||||
[5.936874, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[5.937167, "o", "bash >> "]
|
||||
[5.939502, "o", "m"]
|
||||
[6.120169, "o", "a"]
|
||||
[6.210505, "o", "k"]
|
||||
[6.300671, "o", "e"]
|
||||
[6.390788, "o", " -"]
|
||||
[6.480981, "o", "f"]
|
||||
[6.571285, "o", " "]
|
||||
[6.661457, "o", "e"]
|
||||
[6.751758, "o", "m"]
|
||||
[6.842048, "o", "be"]
|
||||
[7.022576, "o", "d"]
|
||||
[7.112852, "o", "d"]
|
||||
[7.203064, "o", "e"]
|
||||
[7.293421, "o", "d"]
|
||||
[7.383397, "o", "/e"]
|
||||
[7.473873, "o", "m"]
|
||||
[7.564152, "o", "b"]
|
||||
[7.65431, "o", "e"]
|
||||
[7.744607, "o", "d"]
|
||||
[7.925168, "o", "de"]
|
||||
[8.015472, "o", "d"]
|
||||
[8.105767, "o", "."]
|
||||
[8.195936, "o", "m"]
|
||||
[8.286184, "o", "k"]
|
||||
[8.376537, "o", " l"]
|
||||
[8.466624, "o", "i"]
|
||||
[8.557058, "o", "s"]
|
||||
[8.64739, "o", "t"]
|
||||
[8.827942, "o", "-"]
|
||||
[8.91803, "o", "em"]
|
||||
[9.008446, "o", "b"]
|
||||
[9.098742, "o", "e"]
|
||||
[9.189059, "o", "d"]
|
||||
[9.279328, "o", "d"]
|
||||
[9.36965, "o", "ed"]
|
||||
[9.459574, "o", "\r\n"]
|
||||
[10.492826, "o", "files in embedded\r\n"]
|
||||
[10.492943, "o", "['embedded.mk', 'demo.cast', 'record.sh', 'index.md']\r\n"]
|
||||
[12.498865, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[12.498984, "o", "bash >> "]
|
||||
[12.501382, "o", "m"]
|
||||
[12.681906, "o", "a"]
|
||||
[12.7722, "o", "k"]
|
||||
[12.862501, "o", "e"]
|
||||
[12.952783, "o", " -"]
|
||||
[13.043086, "o", "f"]
|
||||
[13.13339, "o", " "]
|
||||
[13.223546, "o", "e"]
|
||||
[13.313887, "o", "m"]
|
||||
[13.40413, "o", "be"]
|
||||
[13.584464, "o", "d"]
|
||||
[13.674721, "o", "d"]
|
||||
[13.764931, "o", "e"]
|
||||
[13.855143, "o", "d"]
|
||||
[13.945476, "o", "/e"]
|
||||
[14.035801, "o", "m"]
|
||||
[14.126086, "o", "b"]
|
||||
[14.216402, "o", "e"]
|
||||
[14.306688, "o", "d"]
|
||||
[14.487263, "o", "de"]
|
||||
[14.577566, "o", "d"]
|
||||
[14.667572, "o", "."]
|
||||
[14.757974, "o", "m"]
|
||||
[14.848201, "o", "k"]
|
||||
[14.938383, "o", " e"]
|
||||
[15.02867, "o", "m"]
|
||||
[15.118961, "o", "b"]
|
||||
[15.2091, "o", "e"]
|
||||
[15.38968, "o", "d"]
|
||||
[15.479924, "o", "de"]
|
||||
[15.570276, "o", "d"]
|
||||
[15.66027, "o", "-"]
|
||||
[15.750729, "o", "b"]
|
||||
[15.84091, "o", "a"]
|
||||
[15.931277, "o", "sh"]
|
||||
[16.021429, "o", "\r\n"]
|
||||
[17.044626, "o", "Is the process running bash? We can check with ps\r\n"]
|
||||
[17.063304, "o", "bash\r\n"]
|
||||
[17.063756, "o", "What text to figlet? \r\n"]
|
||||
[20.107984, "o", "t"]
|
||||
[20.125262, "o", "a"]
|
||||
[20.276406, "o", "s"]
|
||||
[20.454083, "o", "k"]
|
||||
[20.705234, "o", "."]
|
||||
[20.931947, "o", "m"]
|
||||
[21.010096, "o", "k"]
|
||||
[21.288327, "o", "\r\n"]
|
||||
[21.292384, "o", " _ _ _ \r\n| |_ __ _ ___| | __ _ __ ___ | | __\r\n| __/ _` / __| |/ / | '_ ` _ \\| |/ /\r\n| || (_| \\__ \\ < _| | | | | | < \r\n \\__\\__,_|___/_|\\_(_)_| |_| |_|_|\\_\\\r\n \r\n"]
|
||||
[21.292754, "o", "the argument below as given in the makefile itself\r\n"]
|
||||
[21.292898, "o", "it's expanded before the script is passed to bash\r\n"]
|
||||
[21.292925, "o", "bash multiline is probably working\r\n"]
|
||||
{"version": 2, "width": 60, "height": 20, "timestamp": 1664055171, "env": {"SHELL": "/usr/bin/zsh", "TERM": "xterm-256color"}}
|
||||
[0.007548, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[0.007965, "o", "bash >> "]
|
||||
[0.008893, "o", "m"]
|
||||
[0.189592, "o", "a"]
|
||||
[0.279902, "o", "k"]
|
||||
[0.370173, "o", "e"]
|
||||
[0.46048, "o", " -"]
|
||||
[0.550759, "o", "f"]
|
||||
[0.641007, "o", " "]
|
||||
[0.731306, "o", "e"]
|
||||
[0.82157, "o", "m"]
|
||||
[0.91184, "o", "be"]
|
||||
[1.092319, "o", "d"]
|
||||
[1.182603, "o", "d"]
|
||||
[1.272876, "o", "e"]
|
||||
[1.363132, "o", "d"]
|
||||
[1.453425, "o", "/e"]
|
||||
[1.543751, "o", "m"]
|
||||
[1.634046, "o", "b"]
|
||||
[1.724319, "o", "e"]
|
||||
[1.814478, "o", "d"]
|
||||
[1.994943, "o", "de"]
|
||||
[2.08497, "o", "d"]
|
||||
[2.175374, "o", "."]
|
||||
[2.265531, "o", "m"]
|
||||
[2.355687, "o", "k"]
|
||||
[2.446017, "o", " h"]
|
||||
[2.536139, "o", "e"]
|
||||
[2.62642, "o", "l"]
|
||||
[2.716714, "o", "p"]
|
||||
[2.89738, "o", "\r\n"]
|
||||
[3.954163, "o", "\u001b[1;36musage:\u001b[0m\r\n\tmake <recipe>\r\n\t\r\n\texamples of embedded scripts in `\u001b[35mMakefile\u001b[0m`\r\n\r\n \u001b[1;31m examples of task.mk features \u001b[0m\r\n\u001b[38m ─────────────────────────────────────────────────────\u001b[0m\r\n\u001b[1;33m list-%\u001b[0m │ \u001b[2muse pathlib.Path to list files\u001b[0m\r\n \u001b[2mname the directory in rule (make list-src)\u001b[0m\r\n\u001b[1;33m embedded-bash\u001b[0m │ \u001b[2mbash script with pipes and make input\u001b[0m\r\n\u001b[1;33m h, help\u001b[0m │ \u001b[2mshow this help\u001b[0m\r\n\r\n"]
|
||||
[5.96112, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[5.961251, "o", "bash >> "]
|
||||
[5.963433, "o", "m"]
|
||||
[6.143921, "o", "a"]
|
||||
[6.234271, "o", "k"]
|
||||
[6.324575, "o", "e"]
|
||||
[6.414644, "o", " -"]
|
||||
[6.504995, "o", "f"]
|
||||
[6.595278, "o", " "]
|
||||
[6.685565, "o", "e"]
|
||||
[6.775839, "o", "m"]
|
||||
[6.866104, "o", "be"]
|
||||
[7.046619, "o", "d"]
|
||||
[7.13684, "o", "d"]
|
||||
[7.227116, "o", "e"]
|
||||
[7.317391, "o", "d"]
|
||||
[7.407672, "o", "/e"]
|
||||
[7.497991, "o", "m"]
|
||||
[7.588331, "o", "b"]
|
||||
[7.678569, "o", "e"]
|
||||
[7.768707, "o", "d"]
|
||||
[7.949266, "o", "de"]
|
||||
[8.039579, "o", "d"]
|
||||
[8.129824, "o", "."]
|
||||
[8.220093, "o", "m"]
|
||||
[8.31034, "o", "k"]
|
||||
[8.400625, "o", " l"]
|
||||
[8.490922, "o", "i"]
|
||||
[8.58116, "o", "s"]
|
||||
[8.671454, "o", "t"]
|
||||
[8.851981, "o", "-"]
|
||||
[8.942245, "o", "em"]
|
||||
[9.032522, "o", "b"]
|
||||
[9.122833, "o", "e"]
|
||||
[9.213072, "o", "d"]
|
||||
[9.303191, "o", "d"]
|
||||
[9.393526, "o", "ed"]
|
||||
[9.483821, "o", "\r\n"]
|
||||
[10.511808, "o", "files in embedded\r\n['embedded.mk', 'demo.cast', 'record.sh', 'index.md']\r\n"]
|
||||
[12.516872, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[12.516965, "o", "bash >> "]
|
||||
[12.519222, "o", "m"]
|
||||
[12.699954, "o", "a"]
|
||||
[12.79021, "o", "k"]
|
||||
[12.880615, "o", "e"]
|
||||
[12.970893, "o", " -"]
|
||||
[13.060977, "o", "f"]
|
||||
[13.151349, "o", " "]
|
||||
[13.241652, "o", "e"]
|
||||
[13.331738, "o", "m"]
|
||||
[13.422141, "o", "be"]
|
||||
[13.602788, "o", "d"]
|
||||
[13.693079, "o", "d"]
|
||||
[13.78338, "o", "e"]
|
||||
[13.873565, "o", "d"]
|
||||
[13.963954, "o", "/e"]
|
||||
[14.054191, "o", "m"]
|
||||
[14.144518, "o", "b"]
|
||||
[14.234841, "o", "e"]
|
||||
[14.324789, "o", "d"]
|
||||
[14.505231, "o", "de"]
|
||||
[14.595381, "o", "d"]
|
||||
[14.685581, "o", "."]
|
||||
[14.775855, "o", "m"]
|
||||
[14.866138, "o", "k"]
|
||||
[14.956373, "o", " e"]
|
||||
[15.046669, "o", "m"]
|
||||
[15.136992, "o", "b"]
|
||||
[15.227273, "o", "e"]
|
||||
[15.407799, "o", "d"]
|
||||
[15.498095, "o", "de"]
|
||||
[15.58824, "o", "d"]
|
||||
[15.678556, "o", "-"]
|
||||
[15.768832, "o", "b"]
|
||||
[15.859114, "o", "a"]
|
||||
[15.949388, "o", "sh"]
|
||||
[16.039697, "o", "\r\n"]
|
||||
[17.054528, "o", "Is the process running bash? We can check with ps\r\n"]
|
||||
[17.067654, "o", "bash\r\n"]
|
||||
[17.06844, "o", "What text to figlet? \r\n"]
|
||||
[18.253061, "o", "t"]
|
||||
[18.321446, "o", "a"]
|
||||
[18.407375, "o", "s"]
|
||||
[18.517678, "o", "k"]
|
||||
[18.724567, "o", "."]
|
||||
[18.983186, "o", "m"]
|
||||
[19.122527, "o", "k"]
|
||||
[19.555889, "o", "\r\n"]
|
||||
[19.558381, "o", " _ _ _ \r\n| |_ __ _ ___| | __ _ __ ___ | | __\r\n| __/ _` / __| |/ / | '_ ` _ \\| |/ /\r\n| || (_| \\__ \\ < _| | | | | | < \r\n \\__\\__,_|___/_|\\_(_)_| |_| |_|_|\\_\\\r\n \r\n"]
|
||||
[19.558838, "o", "the argument below as given in the makefile itself\r\nit's expanded before the script is passed to bash\r\n"]
|
||||
[19.559049, "o", "bash multiline is probably working\r\n"]
|
||||
|
|
|
@ -5,4 +5,5 @@ source "$(dirname "${BASH_SOURCE[0]}")/../functions.sh"
|
|||
cmd 'make -f embedded/embedded.mk help'
|
||||
cmd 'make -f embedded/embedded.mk list-embedded'
|
||||
cmd 'make -f embedded/embedded.mk embedded-bash'
|
||||
sleep 1
|
||||
|
||||
|
|
38
src/utils.py
38
src/utils.py
|
@ -8,13 +8,7 @@ from dataclasses import dataclass
|
|||
|
||||
@dataclass
|
||||
class Config:
|
||||
header: str
|
||||
accent: str
|
||||
params: str
|
||||
goal: str
|
||||
msg: str
|
||||
div: str
|
||||
div_style: str
|
||||
sep: str
|
||||
epilog: str
|
||||
usage: str
|
||||
|
@ -56,6 +50,7 @@ class Ansi:
|
|||
)
|
||||
for name, byte in state2byte.items():
|
||||
self.setcode(name, f"\033[{byte}m")
|
||||
self.add_cfg()
|
||||
|
||||
def setcode(self, name, escape_code):
|
||||
"""create attr for style and escape code"""
|
||||
|
@ -93,14 +88,17 @@ class Ansi:
|
|||
|
||||
return code + end
|
||||
|
||||
def add_cfg(self, cfg):
|
||||
cfg_attrs = {
|
||||
attr: getattr(cfg, attr)
|
||||
for attr in cfg.__dict__
|
||||
if attr not in ["div", "sep", "epilog", "usage"]
|
||||
def add_cfg(self):
|
||||
cfg_styles = {
|
||||
"header": "$(HEADER_STYLE)",
|
||||
"accent": "$(ACCENT_STYLE)",
|
||||
"params": "$(PARAMS_STYLE)",
|
||||
"goal": "$(GOAL_STYLE)",
|
||||
"msg": "$(MSG_STYLE)",
|
||||
"div_style": "$(DIVIDER_STYLE)",
|
||||
}
|
||||
for name, cfg_attr in cfg_attrs.items():
|
||||
self.setcode(name, getattr(ansi, cfg_attr))
|
||||
for name, style in cfg_styles.items():
|
||||
self.setcode(name, getattr(self, style))
|
||||
|
||||
def style(self, text, style):
|
||||
if style not in self.__dict__:
|
||||
|
@ -112,17 +110,5 @@ class Ansi:
|
|||
|
||||
a = ansi = Ansi()
|
||||
|
||||
cfg = Config(
|
||||
"$(HEADER_STYLE)",
|
||||
"$(ACCENT_STYLE)",
|
||||
"$(PARAMS_STYLE)",
|
||||
"$(GOAL_STYLE)",
|
||||
"$(MSG_STYLE)",
|
||||
"$(DIVIDER)",
|
||||
"$(DIVIDER_STYLE)",
|
||||
"$(HELP_SEP)",
|
||||
f"""$(EPILOG)""",
|
||||
f"""$(USAGE)""",
|
||||
)
|
||||
ansi.add_cfg(cfg)
|
||||
cfg = Config("$(DIVIDER)", "$(HELP_SEP)", f"""$(EPILOG)""", f"""$(USAGE)""")
|
||||
#% endblock %#
|
||||
|
|
40
task.mk
40
task.mk
|
@ -1,7 +1,7 @@
|
|||
# }> [github.com/daylinmorgan/task.mk] <{ #
|
||||
# Copyright (c) 2022 Daylin Morgan
|
||||
# MIT License
|
||||
# version: v22.9.19-12-gbc4c95a-dev
|
||||
# version: v22.9.19-13-g63eb8ac-dev
|
||||
#
|
||||
# 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.
|
||||
|
@ -280,13 +280,7 @@ import sys
|
|||
from dataclasses import dataclass
|
||||
@dataclass
|
||||
class Config:
|
||||
header: str
|
||||
accent: str
|
||||
params: str
|
||||
goal: str
|
||||
msg: str
|
||||
div: str
|
||||
div_style: str
|
||||
sep: str
|
||||
epilog: str
|
||||
usage: str
|
||||
|
@ -321,6 +315,7 @@ class Ansi:
|
|||
)
|
||||
for name, byte in state2byte.items():
|
||||
self.setcode(name, f"\033[{byte}m")
|
||||
self.add_cfg()
|
||||
def setcode(self, name, escape_code):
|
||||
"""create attr for style and escape code"""
|
||||
if not sys.stdout.isatty() or os.getenv("NO_COLOR", False):
|
||||
|
@ -351,14 +346,17 @@ class Ansi:
|
|||
print("Expected one or three values for bg as a list")
|
||||
sys.exit(1)
|
||||
return code + end
|
||||
def add_cfg(self, cfg):
|
||||
cfg_attrs = {
|
||||
attr: getattr(cfg, attr)
|
||||
for attr in cfg.__dict__
|
||||
if attr not in ["div", "sep", "epilog", "usage"]
|
||||
def add_cfg(self):
|
||||
cfg_styles = {
|
||||
"header": "$(HEADER_STYLE)",
|
||||
"accent": "$(ACCENT_STYLE)",
|
||||
"params": "$(PARAMS_STYLE)",
|
||||
"goal": "$(GOAL_STYLE)",
|
||||
"msg": "$(MSG_STYLE)",
|
||||
"div_style": "$(DIVIDER_STYLE)",
|
||||
}
|
||||
for name, cfg_attr in cfg_attrs.items():
|
||||
self.setcode(name, getattr(ansi, cfg_attr))
|
||||
for name, style in cfg_styles.items():
|
||||
self.setcode(name, getattr(self, style))
|
||||
def style(self, text, style):
|
||||
if style not in self.__dict__:
|
||||
print(f"unknown style: {style}")
|
||||
|
@ -366,17 +364,5 @@ class Ansi:
|
|||
else:
|
||||
return f"{self.__dict__[style]}{text}{self.__dict__['end']}"
|
||||
a = ansi = Ansi()
|
||||
cfg = Config(
|
||||
"$(HEADER_STYLE)",
|
||||
"$(ACCENT_STYLE)",
|
||||
"$(PARAMS_STYLE)",
|
||||
"$(GOAL_STYLE)",
|
||||
"$(MSG_STYLE)",
|
||||
"$(DIVIDER)",
|
||||
"$(DIVIDER_STYLE)",
|
||||
"$(HELP_SEP)",
|
||||
f"""$(EPILOG)""",
|
||||
f"""$(USAGE)""",
|
||||
)
|
||||
ansi.add_cfg(cfg)
|
||||
cfg = Config("$(DIVIDER)", "$(HELP_SEP)", f"""$(EPILOG)""", f"""$(USAGE)""")
|
||||
endef
|
||||
|
|
Loading…
Reference in a new issue