mirror of
https://github.com/daylinmorgan/task.mk.git
synced 2024-12-22 18:00:44 -06:00
Compare commits
3 commits
c137951ee0
...
a980d51369
Author | SHA1 | Date | |
---|---|---|---|
a980d51369 | |||
9ee6d34ecf | |||
6f57d43ddc |
6 changed files with 38 additions and 17 deletions
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
TASKMK_VERSION=v23.1.1
|
LATEST_TASKMK_VERSION="v23.1.1"
|
||||||
VERSION=${1:-$TASKMK_VERSION}
|
VERSION=${TASKMK_VERSION:-$LATEST_TASKMK_VERSION}
|
||||||
printf "Initializing Task.mk (%s) for repo\n" "$VERSION"
|
printf "Initializing Task.mk (%s) for repo\n" "$VERSION"
|
||||||
if [ -f "./.task.mk" ]; then
|
if [ -f "./.task.mk" ]; then
|
||||||
echo "Found local .task.mk."
|
echo "Found local .task.mk."
|
||||||
|
@ -11,7 +11,7 @@ if [ -f "./.task.mk" ]; then
|
||||||
fi
|
fi
|
||||||
curl -fsSL "https://raw.githubusercontent.com/daylinmorgan/task.mk/$VERSION/task.mk" -o .task.mk
|
curl -fsSL "https://raw.githubusercontent.com/daylinmorgan/task.mk/$VERSION/task.mk" -o .task.mk
|
||||||
echo .task.mk >>.gitignore
|
echo .task.mk >>.gitignore
|
||||||
echo '-include .task.cfg.mk .task.mk' >>Makefile
|
printf '\n-include .task.cfg.mk .task.mk\n' >>Makefile
|
||||||
printf '$(if $(filter help,$(MAKECMDGOALS)),$(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/%s/task.mk -o .task.mk))' \
|
printf '$(if $(filter help,$(MAKECMDGOALS)),$(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/%s/task.mk -o .task.mk))' \
|
||||||
"$VERSION" \
|
"$VERSION" \
|
||||||
>>Makefile
|
>>Makefile
|
||||||
|
|
|
@ -92,8 +92,8 @@ def fmt_goal(goal, msg, max_goal_len, argstr):
|
||||||
args = parseargs(argstr)
|
args = parseargs(argstr)
|
||||||
goal_style = args.goal_style.strip() if args.goal_style else "goal"
|
goal_style = args.goal_style.strip() if args.goal_style else "goal"
|
||||||
msg_style = args.msg_style.strip() if args.msg_style else "msg"
|
msg_style = args.msg_style.strip() if args.msg_style else "msg"
|
||||||
# TODO: refactor this to be closer to parse_goal?
|
###- TODO: refactor this to be closer to parse_goal? -###
|
||||||
if not msg or (not os.getenv("SHOW_HIDDEN") and args.hidden):
|
if not os.getenv("SHOW_HIDDEN") and args.hidden:
|
||||||
return
|
return
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -112,14 +112,14 @@ def fmt_rawmsg(msg, argstr, maxlens):
|
||||||
if msg:
|
if msg:
|
||||||
if args.align == "sep":
|
if args.align == "sep":
|
||||||
lines.append(
|
lines.append(
|
||||||
f"{' '*(maxlens.goal+len(cfg.sep)+4)}{ansi.style(msg,msg_style)}"
|
f"{' '*(maxlens.goal+len(strip_ansi(cfg.sep))+4)}{ansi.style(msg,msg_style)}"
|
||||||
)
|
)
|
||||||
elif args.align == "center":
|
elif args.align == "center":
|
||||||
lines.append(f" {ansi.style(msg.center(sum(maxlens)),msg_style)}")
|
lines.append(f" {ansi.style(msg.center(sum(maxlens)),msg_style)}")
|
||||||
else:
|
else:
|
||||||
lines.append(f" {ansi.style(msg,msg_style)}")
|
lines.append(f" {ansi.style(msg,msg_style)}")
|
||||||
if args.divider:
|
if args.divider:
|
||||||
lines.append(divider(len(cfg.sep) + sum(maxlens) + 2))
|
lines.append(divider(len(strip_ansi(cfg.sep)) + sum(maxlens) + 2))
|
||||||
if args.whitespace:
|
if args.whitespace:
|
||||||
lines.append("\n")
|
lines.append("\n")
|
||||||
|
|
||||||
|
@ -130,6 +130,7 @@ def print_help():
|
||||||
lines = [cfg.usage]
|
lines = [cfg.usage]
|
||||||
|
|
||||||
items = list(parse_help(gen_makefile()))
|
items = list(parse_help(gen_makefile()))
|
||||||
|
###- TODO: filter items before this step no msg no care -###
|
||||||
maxlens = MaxLens(
|
maxlens = MaxLens(
|
||||||
*(
|
*(
|
||||||
max((*(len(item[x]) for item in items if x in item), 0))
|
max((*(len(item[x]) for item in items if x in item), 0))
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
#% extends "py-script.mk" %#
|
#% extends "py-script.mk" %#
|
||||||
#% block name %#parsers#% endblock %#
|
#% block name %#parsers#% endblock %#
|
||||||
#% block script %#
|
#% block script %#
|
||||||
import re
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
###- LSP TRICK ONLY
|
###- LSP TRICK ONLY
|
||||||
import os, sys
|
import os, re, sys
|
||||||
|
|
||||||
# -###
|
# -###
|
||||||
|
|
||||||
|
@ -53,6 +52,8 @@ def parse_help(file, hidden=False):
|
||||||
and str(match.groupdict().get("goal")).startswith("_")
|
and str(match.groupdict().get("goal")).startswith("_")
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
elif not any(match.groupdict().get(k) for k in ('msg','msgargs')):
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
yield {k: v for k, v in match.groupdict().items() if v is not None}
|
yield {k: v for k, v in match.groupdict().items() if v is not None}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ codes_names = {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for code in sorted(codes_names.keys(), key=lambda item: (len(item), item)):
|
for code in sorted(codes_names.keys(), key=lambda item: (len(item), item)):
|
||||||
sys.stderr.write(
|
sys.stderr.write(
|
||||||
f"{codes_names[code]:>20} {cfg.sep} {code+'*****'+ansi.end} {cfg.sep} {repr(code)}\n"
|
f"{codes_names[code]:>20} {cfg.sep} {code+'*****'+ansi.end} {cfg.sep} {repr(code)}\n"
|
||||||
|
|
10
src/utils.py
10
src/utils.py
|
@ -2,9 +2,17 @@
|
||||||
#% block name %#utils#% endblock %#
|
#% block name %#utils#% endblock %#
|
||||||
#% block script %#
|
#% block script %#
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
def strip_ansi(txt):
|
||||||
|
"""
|
||||||
|
Removes ANSI escape codes, as defined by ECMA-048 in
|
||||||
|
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf
|
||||||
|
"""
|
||||||
|
pattern = re.compile(r'\x1B\[\d+(;\d+){0,2}m')
|
||||||
|
return pattern.sub('', txt)
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Config:
|
class Config:
|
||||||
|
@ -121,6 +129,6 @@ class Ansi:
|
||||||
a = ansi = Ansi()
|
a = ansi = Ansi()
|
||||||
###- the below $() variables are injected by make -###
|
###- the below $() variables are injected by make -###
|
||||||
cfg = Config(
|
cfg = Config(
|
||||||
"$(DIVIDER)", "$(HELP_SEP)", f"""$(EPILOG)""", f"""$(USAGE)""", int("$(WRAP)")
|
"$(DIVIDER)", f"""$(HELP_SEP)""", f"""$(EPILOG)""", f"""$(USAGE)""", int("$(WRAP)")
|
||||||
)
|
)
|
||||||
#% endblock %#
|
#% endblock %#
|
||||||
|
|
24
task.mk
24
task.mk
|
@ -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
|
||||||
TASKMK_VERSION ?= v23.1.1-2-g25666e8-dev
|
TASKMK_VERSION ?= v23.1.1-5-g9ee6d34-dev
|
||||||
# task.mk should be included at the bottom of your Makefile with `-include .task.mk`
|
# 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.
|
# See below for the standard configuration options that should be set prior to including this file.
|
||||||
# You can update your .task.mk with `make _update-task.mk`
|
# You can update your .task.mk with `make _update-task.mk`
|
||||||
|
@ -92,8 +92,8 @@ def fmt_goal(goal, msg, max_goal_len, argstr):
|
||||||
args = parseargs(argstr)
|
args = parseargs(argstr)
|
||||||
goal_style = args.goal_style.strip() if args.goal_style else "goal"
|
goal_style = args.goal_style.strip() if args.goal_style else "goal"
|
||||||
msg_style = args.msg_style.strip() if args.msg_style else "msg"
|
msg_style = args.msg_style.strip() if args.msg_style else "msg"
|
||||||
# TODO: refactor this to be closer to parse_goal?
|
|
||||||
if not msg or (not os.getenv("SHOW_HIDDEN") and args.hidden):
|
if not os.getenv("SHOW_HIDDEN") and args.hidden:
|
||||||
return
|
return
|
||||||
return (
|
return (
|
||||||
ansi.style(f" {goal:>{max_goal_len}}", goal_style)
|
ansi.style(f" {goal:>{max_goal_len}}", goal_style)
|
||||||
|
@ -109,20 +109,21 @@ def fmt_rawmsg(msg, argstr, maxlens):
|
||||||
if msg:
|
if msg:
|
||||||
if args.align == "sep":
|
if args.align == "sep":
|
||||||
lines.append(
|
lines.append(
|
||||||
f"{' '*(maxlens.goal+len(cfg.sep)+4)}{ansi.style(msg,msg_style)}"
|
f"{' '*(maxlens.goal+len(strip_ansi(cfg.sep))+4)}{ansi.style(msg,msg_style)}"
|
||||||
)
|
)
|
||||||
elif args.align == "center":
|
elif args.align == "center":
|
||||||
lines.append(f" {ansi.style(msg.center(sum(maxlens)),msg_style)}")
|
lines.append(f" {ansi.style(msg.center(sum(maxlens)),msg_style)}")
|
||||||
else:
|
else:
|
||||||
lines.append(f" {ansi.style(msg,msg_style)}")
|
lines.append(f" {ansi.style(msg,msg_style)}")
|
||||||
if args.divider:
|
if args.divider:
|
||||||
lines.append(divider(len(cfg.sep) + sum(maxlens) + 2))
|
lines.append(divider(len(strip_ansi(cfg.sep)) + sum(maxlens) + 2))
|
||||||
if args.whitespace:
|
if args.whitespace:
|
||||||
lines.append("\n")
|
lines.append("\n")
|
||||||
return lines
|
return lines
|
||||||
def print_help():
|
def print_help():
|
||||||
lines = [cfg.usage]
|
lines = [cfg.usage]
|
||||||
items = list(parse_help(gen_makefile()))
|
items = list(parse_help(gen_makefile()))
|
||||||
|
|
||||||
maxlens = MaxLens(
|
maxlens = MaxLens(
|
||||||
*(
|
*(
|
||||||
max((*(len(item[x]) for item in items if x in item), 0))
|
max((*(len(item[x]) for item in items if x in item), 0))
|
||||||
|
@ -210,8 +211,16 @@ else:
|
||||||
endef
|
endef
|
||||||
define utils_py
|
define utils_py
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
def strip_ansi(txt):
|
||||||
|
"""
|
||||||
|
Removes ANSI escape codes, as defined by ECMA-048 in
|
||||||
|
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf
|
||||||
|
"""
|
||||||
|
pattern = re.compile(r'\x1B\[\d+(;\d+){0,2}m')
|
||||||
|
return pattern.sub('', txt)
|
||||||
@dataclass
|
@dataclass
|
||||||
class Config:
|
class Config:
|
||||||
div: str
|
div: str
|
||||||
|
@ -309,7 +318,7 @@ class Ansi:
|
||||||
return f"{self.__dict__[style]}{text}{self.__dict__['end']}"
|
return f"{self.__dict__[style]}{text}{self.__dict__['end']}"
|
||||||
a = ansi = Ansi()
|
a = ansi = Ansi()
|
||||||
cfg = Config(
|
cfg = Config(
|
||||||
"$(DIVIDER)", "$(HELP_SEP)", f"""$(EPILOG)""", f"""$(USAGE)""", int("$(WRAP)")
|
"$(DIVIDER)", f"""$(HELP_SEP)""", f"""$(EPILOG)""", f"""$(USAGE)""", int("$(WRAP)")
|
||||||
)
|
)
|
||||||
endef
|
endef
|
||||||
define phonify_py
|
define phonify_py
|
||||||
|
@ -327,7 +336,6 @@ if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
endef
|
endef
|
||||||
define parsers_py
|
define parsers_py
|
||||||
import re
|
|
||||||
import argparse
|
import argparse
|
||||||
$(utils_py)
|
$(utils_py)
|
||||||
pattern = re.compile(
|
pattern = re.compile(
|
||||||
|
@ -365,6 +373,8 @@ def parse_help(file, hidden=False):
|
||||||
and str(match.groupdict().get("goal")).startswith("_")
|
and str(match.groupdict().get("goal")).startswith("_")
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
elif not any(match.groupdict().get(k) for k in ('msg','msgargs')):
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
yield {k: v for k, v in match.groupdict().items() if v is not None}
|
yield {k: v for k, v in match.groupdict().items() if v is not None}
|
||||||
def parseargs(argstring):
|
def parseargs(argstring):
|
||||||
|
|
Loading…
Reference in a new issue