mirror of
https://github.com/daylinmorgan/task.mk.git
synced 2024-12-22 01:50:44 -06:00
Compare commits
7 commits
77e76edd16
...
e608a90b5a
Author | SHA1 | Date | |
---|---|---|---|
e608a90b5a | |||
c85f5f8103 | |||
5f593e35c8 | |||
071f7fc991 | |||
1da492e9c3 | |||
580c9ff76f | |||
031e38a0aa |
18 changed files with 461 additions and 326 deletions
|
@ -24,7 +24,7 @@ Current Features:
|
|||
- custom print function
|
||||
- confirmation prompt
|
||||
|
||||
Depends on `GNU Make`, obviously and `Python >=3.7`.
|
||||
Depends on `GNU Make`, obviously and `Python >=3.7`, and `bash` (or `zsh`).
|
||||
|
||||
Wait python?!?!, I'm not `pip` installing some package just to parse my makefile.
|
||||
I agree, all you need is one file [`.task.mk`](./task.mk).
|
||||
|
|
|
@ -9,7 +9,7 @@ all: $(CASTS)
|
|||
%/demo.cast: %/record.sh
|
||||
asciinema rec --cols $(COLS) --rows $(ROWS) --overwrite -c $< $@
|
||||
|
||||
check/demo.cast: COLS = 45
|
||||
check/demo.cast: COLS = 48
|
||||
check/demo.cast: ROWS = 12
|
||||
|
||||
clean:
|
||||
|
|
|
@ -11,6 +11,6 @@ define USAGE
|
|||
interactivity w/ task.mk\n
|
||||
endef
|
||||
|
||||
.DEFUALT_GOAL = help
|
||||
.DEFAULT_GOAL = help
|
||||
include $(shell git rev-parse --show-toplevel)/task.mk
|
||||
|
||||
|
|
|
@ -1,130 +1,129 @@
|
|||
{"version": 2, "width": 45, "height": 12, "timestamp": 1663509712, "env": {"SHELL": "/usr/bin/zsh", "TERM": "xterm-256color"}}
|
||||
[0.007004, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[0.007499, "o", "bash >> "]
|
||||
[0.007695, "o", "m"]
|
||||
[0.188475, "o", "a"]
|
||||
[0.278605, "o", "k"]
|
||||
[0.368932, "o", "e"]
|
||||
[0.459055, "o", " -"]
|
||||
[0.549199, "o", "f"]
|
||||
[0.639392, "o", " "]
|
||||
[0.729414, "o", "c"]
|
||||
[0.81952, "o", "h"]
|
||||
[0.909732, "o", "ec"]
|
||||
[1.090009, "o", "k"]
|
||||
[1.180084, "o", "/"]
|
||||
[1.270256, "o", "c"]
|
||||
[1.360329, "o", "h"]
|
||||
[1.450517, "o", "ec"]
|
||||
[1.540604, "o", "k"]
|
||||
[1.630898, "o", "."]
|
||||
[1.72087, "o", "m"]
|
||||
[1.811036, "o", "k"]
|
||||
[1.991393, "o", " h"]
|
||||
[2.081431, "o", "e"]
|
||||
[2.171549, "o", "l"]
|
||||
[2.261684, "o", "p"]
|
||||
[2.351833, "o", "\r\n"]
|
||||
[3.373753, "o", "\u001b[1;36musage:\u001b[0m\r\n\tmake <recipe>\r\n\t\r\n\tinteractivity w/ task.mk\r\n\r\n\u001b[1;33m check\u001b[0m │ \u001b[2mget user confirmation or exit\u001b[0m\r\n\u001b[1;33m h, help\u001b[0m │ \u001b[2mshow this help\u001b[0m\r\n\r\n"]
|
||||
[5.378629, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[5.37884, "o", "bash >> "]
|
||||
[5.380877, "o", "m"]
|
||||
[5.561187, "o", "a"]
|
||||
[5.651259, "o", "k"]
|
||||
[5.741367, "o", "e"]
|
||||
[5.83161, "o", " -"]
|
||||
[5.921765, "o", "f"]
|
||||
[6.011971, "o", " "]
|
||||
[6.102115, "o", "c"]
|
||||
[6.192388, "o", "h"]
|
||||
[6.282346, "o", "ec"]
|
||||
[6.462683, "o", "k"]
|
||||
[6.552812, "o", "/"]
|
||||
[6.642847, "o", "c"]
|
||||
[6.73297, "o", "h"]
|
||||
[6.823099, "o", "ec"]
|
||||
[6.913297, "o", "k"]
|
||||
[7.003515, "o", "."]
|
||||
[7.093594, "o", "m"]
|
||||
[7.183719, "o", "k"]
|
||||
[7.364474, "o", " c"]
|
||||
[7.454638, "o", "h"]
|
||||
[7.544856, "o", "e"]
|
||||
[7.634908, "o", "c"]
|
||||
[7.725037, "o", "k"]
|
||||
[7.815191, "o", "\r\n"]
|
||||
[8.827899, "o", "Would you like to proceed? \u001b[1;31m[Y/n]\u001b[0m "]
|
||||
[9.751154, "o", "y"]
|
||||
[9.837618, "o", "\r\n"]
|
||||
[9.846779, "o", "you said yes!\r\n"]
|
||||
[11.850338, "o", "#"]
|
||||
[12.030527, "o", " "]
|
||||
[12.12062, "o", "L"]
|
||||
[12.210763, "o", "e"]
|
||||
[12.300857, "o", "t'"]
|
||||
[12.391099, "o", "s"]
|
||||
[12.481244, "o", " "]
|
||||
[12.57145, "o", "t"]
|
||||
[12.66148, "o", "r"]
|
||||
[12.751606, "o", "y "]
|
||||
[12.932134, "o", "a"]
|
||||
[13.022101, "o", "g"]
|
||||
[13.112244, "o", "a"]
|
||||
[13.202336, "o", "i"]
|
||||
[13.292469, "o", "n "]
|
||||
[13.38261, "o", "b"]
|
||||
[13.472767, "o", "u"]
|
||||
[13.562841, "o", "t"]
|
||||
[13.652944, "o", " "]
|
||||
[13.833164, "o", "in"]
|
||||
[13.923274, "o", "s"]
|
||||
[14.013422, "o", "t"]
|
||||
[14.10364, "o", "e"]
|
||||
[14.193783, "o", "a"]
|
||||
[14.283859, "o", "d "]
|
||||
[14.374022, "o", "s"]
|
||||
[14.464304, "o", "a"]
|
||||
[14.554416, "o", "y"]
|
||||
[14.734528, "o", " "]
|
||||
[14.824636, "o", "no"]
|
||||
[14.914924, "o", " "]
|
||||
[15.005102, "o", "t"]
|
||||
[15.095117, "o", "h"]
|
||||
[15.185276, "o", "i"]
|
||||
[15.275414, "o", "s "]
|
||||
[15.365521, "o", "t"]
|
||||
[15.45574, "o", "i"]
|
||||
[15.635918, "o", "m"]
|
||||
[15.726033, "o", "e"]
|
||||
[15.816169, "o", "\r\n"]
|
||||
[16.817697, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[16.817793, "o", "bash >> "]
|
||||
[16.818364, "o", "m"]
|
||||
[16.999104, "o", "a"]
|
||||
[17.089183, "o", "k"]
|
||||
[17.179376, "o", "e"]
|
||||
[17.269421, "o", " -"]
|
||||
[17.359516, "o", "f"]
|
||||
[17.449715, "o", " "]
|
||||
[17.539785, "o", "c"]
|
||||
[17.629954, "o", "h"]
|
||||
[17.720065, "o", "ec"]
|
||||
[17.900294, "o", "k"]
|
||||
[17.990472, "o", "/"]
|
||||
[18.080485, "o", "c"]
|
||||
[18.170674, "o", "h"]
|
||||
[18.260717, "o", "ec"]
|
||||
[18.350924, "o", "k"]
|
||||
[18.441115, "o", "."]
|
||||
[18.531291, "o", "m"]
|
||||
[18.621449, "o", "k"]
|
||||
[18.801717, "o", " c"]
|
||||
[18.891834, "o", "h"]
|
||||
[18.982112, "o", "e"]
|
||||
[19.07216, "o", "c"]
|
||||
[19.162471, "o", "k"]
|
||||
[19.252562, "o", "\r\n"]
|
||||
[20.265973, "o", "Would you like to proceed? \u001b[1;31m[Y/n]\u001b[0m "]
|
||||
[21.947847, "o", "n"]
|
||||
[22.001462, "o", "\r\n"]
|
||||
[22.00656, "o", "make[1]: *** [check/check.mk:8: check] Error 1\r\n"]
|
||||
{"version": 2, "width": 48, "height": 12, "timestamp": 1663712361, "env": {"SHELL": "/usr/bin/zsh", "TERM": "xterm-256color"}}
|
||||
[0.008114, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[0.00852, "o", "bash >> "]
|
||||
[0.008755, "o", "m"]
|
||||
[0.189398, "o", "a"]
|
||||
[0.279744, "o", "k"]
|
||||
[0.369775, "o", "e"]
|
||||
[0.459919, "o", " -"]
|
||||
[0.549908, "o", "f"]
|
||||
[0.639982, "o", " "]
|
||||
[0.730339, "o", "c"]
|
||||
[0.820338, "o", "h"]
|
||||
[0.910414, "o", "ec"]
|
||||
[1.090651, "o", "k"]
|
||||
[1.18077, "o", "/"]
|
||||
[1.271098, "o", "c"]
|
||||
[1.361098, "o", "h"]
|
||||
[1.451216, "o", "ec"]
|
||||
[1.541276, "o", "k"]
|
||||
[1.631388, "o", "."]
|
||||
[1.721603, "o", "m"]
|
||||
[1.811718, "o", "k"]
|
||||
[1.992079, "o", " h"]
|
||||
[2.082138, "o", "e"]
|
||||
[2.172379, "o", "l"]
|
||||
[2.262403, "o", "p"]
|
||||
[2.352473, "o", "\r\n"]
|
||||
[3.381969, "o", "\u001b[1;36musage:\u001b[0m\r\n\tmake <recipe>\r\n\t\r\n\tinteractivity w/ task.mk\r\n\r\n\u001b[1;33m check\u001b[0m │ \u001b[2mget user confirmation or exit\u001b[0m\r\n\u001b[1;33m h, help\u001b[0m │ \u001b[2mshow this help\u001b[0m\r\n\r\n"]
|
||||
[5.387545, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[5.387892, "o", "bash >> "]
|
||||
[5.390047, "o", "m"]
|
||||
[5.570645, "o", "a"]
|
||||
[5.660579, "o", "k"]
|
||||
[5.750852, "o", "e"]
|
||||
[5.841071, "o", " -"]
|
||||
[5.931225, "o", "f"]
|
||||
[6.021286, "o", " "]
|
||||
[6.111373, "o", "c"]
|
||||
[6.201586, "o", "h"]
|
||||
[6.291778, "o", "ec"]
|
||||
[6.472054, "o", "k"]
|
||||
[6.562124, "o", "/"]
|
||||
[6.652262, "o", "c"]
|
||||
[6.74248, "o", "h"]
|
||||
[6.832675, "o", "ec"]
|
||||
[6.922668, "o", "k"]
|
||||
[7.012809, "o", "."]
|
||||
[7.102973, "o", "m"]
|
||||
[7.193151, "o", "k"]
|
||||
[7.373458, "o", " c"]
|
||||
[7.463783, "o", "h"]
|
||||
[7.553761, "o", "e"]
|
||||
[7.643931, "o", "c"]
|
||||
[7.734197, "o", "k"]
|
||||
[7.824356, "o", "\r\n"]
|
||||
[8.857505, "o", "Would you like to proceed? \u001b[1;31m[Y/n]\u001b[0m "]
|
||||
[9.54018, "o", "y"]
|
||||
[9.595198, "o", "\r\n"]
|
||||
[9.598684, "o", "you said yes!\r\n"]
|
||||
[11.602689, "o", "#"]
|
||||
[11.783071, "o", " "]
|
||||
[11.873235, "o", "L"]
|
||||
[11.963465, "o", "e"]
|
||||
[12.053444, "o", "t'"]
|
||||
[12.143548, "o", "s"]
|
||||
[12.233881, "o", " "]
|
||||
[12.323915, "o", "t"]
|
||||
[12.41414, "o", "r"]
|
||||
[12.50428, "o", "y "]
|
||||
[12.684471, "o", "a"]
|
||||
[12.774773, "o", "g"]
|
||||
[12.864864, "o", "a"]
|
||||
[12.954989, "o", "i"]
|
||||
[13.045011, "o", "n "]
|
||||
[13.135204, "o", "b"]
|
||||
[13.225451, "o", "u"]
|
||||
[13.315649, "o", "t"]
|
||||
[13.405687, "o", " "]
|
||||
[13.585943, "o", "in"]
|
||||
[13.676051, "o", "s"]
|
||||
[13.766346, "o", "t"]
|
||||
[13.856324, "o", "e"]
|
||||
[13.946542, "o", "a"]
|
||||
[14.036697, "o", "d "]
|
||||
[14.126782, "o", "s"]
|
||||
[14.216944, "o", "a"]
|
||||
[14.307128, "o", "y"]
|
||||
[14.487468, "o", " "]
|
||||
[14.577551, "o", "no"]
|
||||
[14.667739, "o", " "]
|
||||
[14.757899, "o", "t"]
|
||||
[14.848007, "o", "h"]
|
||||
[14.93806, "o", "i"]
|
||||
[15.0283, "o", "s "]
|
||||
[15.118379, "o", "t"]
|
||||
[15.208471, "o", "i"]
|
||||
[15.388757, "o", "m"]
|
||||
[15.47897, "o", "e"]
|
||||
[15.569031, "o", "\r\n"]
|
||||
[16.571969, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[16.572047, "o", "bash >> "]
|
||||
[16.574017, "o", "m"]
|
||||
[16.754499, "o", "a"]
|
||||
[16.844612, "o", "k"]
|
||||
[16.93468, "o", "e"]
|
||||
[17.024972, "o", " -"]
|
||||
[17.115137, "o", "f"]
|
||||
[17.205244, "o", " "]
|
||||
[17.295415, "o", "c"]
|
||||
[17.385554, "o", "h"]
|
||||
[17.475882, "o", "ec"]
|
||||
[17.655989, "o", "k"]
|
||||
[17.746279, "o", "/"]
|
||||
[17.83643, "o", "c"]
|
||||
[17.926644, "o", "h"]
|
||||
[18.016673, "o", "ec"]
|
||||
[18.106718, "o", "k"]
|
||||
[18.197045, "o", "."]
|
||||
[18.287031, "o", "m"]
|
||||
[18.377151, "o", "k"]
|
||||
[18.55735, "o", " c"]
|
||||
[18.647478, "o", "h"]
|
||||
[18.737616, "o", "e"]
|
||||
[18.827879, "o", "c"]
|
||||
[18.917992, "o", "k"]
|
||||
[19.008133, "o", "\r\n"]
|
||||
[20.034923, "o", "Would you like to proceed? \u001b[1;31m[Y/n]\u001b[0m "]
|
||||
[22.08808, "o", "n"]
|
||||
[22.227223, "o", "\r\n"]
|
||||
|
|
|
@ -7,4 +7,4 @@ cmd 'make -f check/check.mk check'
|
|||
msg "# Let's try again but instead say no this time"
|
||||
cmd 'make -f check/check.mk check'
|
||||
|
||||
|
||||
sleep 1
|
||||
|
|
|
@ -1,125 +1,126 @@
|
|||
{"version": 2, "width": 60, "height": 20, "timestamp": 1663509736, "env": {"SHELL": "/usr/bin/zsh", "TERM": "xterm-256color"}}
|
||||
[0.006995, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[0.007356, "o", "bash >> "]
|
||||
[0.007626, "o", "m"]
|
||||
[0.188158, "o", "a"]
|
||||
[0.27839, "o", "k"]
|
||||
[0.368576, "o", "e"]
|
||||
[0.458807, "o", " -"]
|
||||
[0.548811, "o", "f"]
|
||||
[0.63903, "o", " "]
|
||||
[0.729091, "o", "e"]
|
||||
[0.819196, "o", "m"]
|
||||
[0.909274, "o", "be"]
|
||||
[1.089691, "o", "d"]
|
||||
[1.179663, "o", "d"]
|
||||
[1.269774, "o", "e"]
|
||||
[1.359973, "o", "d"]
|
||||
[1.450027, "o", "/e"]
|
||||
[1.540296, "o", "m"]
|
||||
[1.630272, "o", "b"]
|
||||
[1.720364, "o", "e"]
|
||||
[1.8106, "o", "d"]
|
||||
[1.990776, "o", "de"]
|
||||
[2.080964, "o", "d"]
|
||||
[2.17101, "o", "."]
|
||||
[2.261109, "o", "m"]
|
||||
[2.351249, "o", "k"]
|
||||
[2.441359, "o", " h"]
|
||||
[2.531512, "o", "e"]
|
||||
[2.621795, "o", "l"]
|
||||
[2.711889, "o", "p"]
|
||||
[2.892394, "o", "\r\n"]
|
||||
[3.915806, "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.921614, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[5.921918, "o", "bash >> "]
|
||||
[5.923943, "o", "m"]
|
||||
[6.104382, "o", "a"]
|
||||
[6.194681, "o", "k"]
|
||||
[6.284819, "o", "e"]
|
||||
[6.375089, "o", " -"]
|
||||
[6.465174, "o", "f"]
|
||||
[6.555322, "o", " "]
|
||||
[6.64533, "o", "e"]
|
||||
[6.735435, "o", "m"]
|
||||
[6.825552, "o", "be"]
|
||||
[7.005939, "o", "d"]
|
||||
[7.096066, "o", "d"]
|
||||
[7.186097, "o", "e"]
|
||||
[7.276232, "o", "d"]
|
||||
[7.366364, "o", "/e"]
|
||||
[7.456527, "o", "m"]
|
||||
[7.546662, "o", "b"]
|
||||
[7.636777, "o", "e"]
|
||||
[7.726911, "o", "d"]
|
||||
[7.907171, "o", "de"]
|
||||
[7.99733, "o", "d"]
|
||||
[8.087458, "o", "."]
|
||||
[8.177539, "o", "m"]
|
||||
[8.26767, "o", "k"]
|
||||
[8.357795, "o", " l"]
|
||||
[8.447911, "o", "i"]
|
||||
[8.538022, "o", "s"]
|
||||
[8.628232, "o", "t"]
|
||||
[8.80841, "o", "-"]
|
||||
[8.898543, "o", "em"]
|
||||
[8.988721, "o", "b"]
|
||||
[9.078836, "o", "e"]
|
||||
[9.169069, "o", "d"]
|
||||
[9.259138, "o", "d"]
|
||||
[9.349222, "o", "ed"]
|
||||
[9.439533, "o", "\r\n"]
|
||||
[10.45661, "o", "files in embedded\r\n['embedded.mk', 'demo.cast', 'record.sh', 'index.md']\r\n"]
|
||||
[12.462317, "o", "\u001b[H\u001b[2J\u001b[3J"]
|
||||
[12.462399, "o", "bash >> "]
|
||||
[12.464413, "o", "m"]
|
||||
[12.644851, "o", "a"]
|
||||
[12.73513, "o", "k"]
|
||||
[12.825178, "o", "e"]
|
||||
[12.91541, "o", " -"]
|
||||
[13.005446, "o", "f"]
|
||||
[13.095515, "o", " "]
|
||||
[13.185598, "o", "e"]
|
||||
[13.275797, "o", "m"]
|
||||
[13.365927, "o", "be"]
|
||||
[13.54612, "o", "d"]
|
||||
[13.636273, "o", "d"]
|
||||
[13.726372, "o", "e"]
|
||||
[13.81653, "o", "d"]
|
||||
[13.906755, "o", "/e"]
|
||||
[13.996972, "o", "m"]
|
||||
[14.08711, "o", "b"]
|
||||
[14.177238, "o", "e"]
|
||||
[14.267423, "o", "d"]
|
||||
[14.447699, "o", "de"]
|
||||
[14.537782, "o", "d"]
|
||||
[14.627908, "o", "."]
|
||||
[14.718053, "o", "m"]
|
||||
[14.808215, "o", "k"]
|
||||
[14.898357, "o", " e"]
|
||||
[14.988612, "o", "m"]
|
||||
[15.078745, "o", "b"]
|
||||
[15.168911, "o", "e"]
|
||||
[15.349036, "o", "d"]
|
||||
[15.439167, "o", "de"]
|
||||
[15.529412, "o", "d"]
|
||||
[15.619518, "o", "-"]
|
||||
[15.709569, "o", "b"]
|
||||
[15.79969, "o", "a"]
|
||||
[15.889938, "o", "sh"]
|
||||
[15.980073, "o", "\r\n"]
|
||||
[16.989864, "o", "Is the process running bash? We can check with ps\r\n"]
|
||||
[16.999039, "o", "bash\r\n"]
|
||||
[16.999517, "o", "What text to figlet? \r\n"]
|
||||
[19.167405, "o", "t"]
|
||||
[19.201071, "o", "a"]
|
||||
[19.292173, "o", "s"]
|
||||
[19.436959, "o", "k"]
|
||||
[19.588588, "o", "."]
|
||||
[19.767086, "o", "m"]
|
||||
[19.903321, "o", "k"]
|
||||
[20.073296, "o", "\r\n"]
|
||||
[20.074356, "o", " _ _ _ \r\n| |_ __ _ ___| | __ _ __ ___ | | __\r\n| __/ _` / __| |/ / | '_ ` _ \\| |/ /\r\n| || (_| \\__ \\ < _| | | | | | < \r\n \\__\\__,_|___/_|\\_(_)_| |_| |_|_|\\_\\\r\n \r\n"]
|
||||
[20.074497, "o", "the argument below as given in the makefile itself\r\n"]
|
||||
[20.074527, "o", "it's expanded before the script is passed to bash\r\n"]
|
||||
[20.074555, "o", "bash multiline is probably working\r\n"]
|
||||
{"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"]
|
||||
|
|
|
@ -38,6 +38,6 @@ define USAGE
|
|||
examples of embedded scripts in `{a.magenta}Makefile{a.end}`
|
||||
|
||||
endef
|
||||
.DEFUALT_GOAL = help
|
||||
.DEFAULT_GOAL = help
|
||||
include $(shell git rev-parse --show-toplevel)/task.mk
|
||||
|
||||
|
|
|
@ -5,3 +5,4 @@ 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'
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ Current Features:
|
|||
- custom print function
|
||||
- confirmation prompt
|
||||
|
||||
Depends on `GNU Make`, obviously and `Python >=3.7`.
|
||||
Depends on `GNU Make`, obviously and `Python >=3.7`, and `bash` (or `zsh`).
|
||||
|
||||
Wait python?!?!, I'm not `pip` installing some package just to parse my makefile.
|
||||
I agree, all you need is one file [`.task.mk`](https://github.com/daylinmorgan/task.mk/v22.9.19/task.mk).
|
||||
|
|
|
@ -56,23 +56,19 @@ See this project's `make info` for an example.
|
|||
You can quickly customize some of the default behavior of `task.mk` by overriding the below variables prior to the `-include .task.mk`.
|
||||
|
||||
```make
|
||||
# ---- CONFIG ---- #
|
||||
# ---- [config] ---- #
|
||||
HEADER_STYLE ?= b_cyan
|
||||
PARAMS_STYLE ?= b_magenta
|
||||
ACCENT_STYLE ?= b_yellow
|
||||
PARAMS_STYLE ?= $(ACCENT_STYLE)
|
||||
GOAL_STYLE ?= $(ACCENT_STYLE)
|
||||
MSG_STYLE ?= faint
|
||||
DIVIDER_STYLE ?= default
|
||||
DIVIDER ?= ─
|
||||
HELP_SEP ?= │
|
||||
|
||||
# python f-string literals
|
||||
EPILOG ?=
|
||||
define USAGE ?=
|
||||
{ansi.$(HEADER_STYLE)}usage{ansi.end}:
|
||||
make <recipe>
|
||||
|
||||
endef
|
||||
USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make <recipe>\n
|
||||
INHERIT_SHELL ?=
|
||||
```
|
||||
|
||||
To use a custom color for one of the predefined configuration variables specify only the custom method.
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import jinja2
|
||||
|
||||
py_script_names = ["help", "ansi", "info", "print-ansi", "vars", "confirm"]
|
||||
py_script_names = ["help", "ansi", "info", "print-ansi", "vars", "confirm", "quit_make"]
|
||||
|
||||
|
||||
def get_jinja_env():
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
# ---- [buitlin recipes] ---- #
|
||||
# ---- [builtin recipes] ---- #
|
||||
ifeq (help,$(firstword $(MAKECMDGOALS)))
|
||||
HELP_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
|
||||
export HELP_ARGS
|
||||
endif
|
||||
## h, help | show this help
|
||||
.PHONY: help h
|
||||
help h:
|
||||
|
@ -27,3 +31,6 @@ _update-task.mk:
|
|||
$(call tprint,{a.b_cyan}Updating task.mk{a.end})
|
||||
curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk
|
||||
export MAKEFILE_LIST
|
||||
ifndef INHERIT_SHELL
|
||||
SHELL := /bin/bash
|
||||
endif
|
||||
|
|
|
@ -10,3 +10,4 @@ HELP_SEP ?= │
|
|||
# python f-string literals
|
||||
EPILOG ?=
|
||||
USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make <recipe>\n
|
||||
INHERIT_SHELL ?=
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import sys
|
||||
|
||||
##- '$(ansi_py)' -##
|
||||
##- '$(quit_make_py)' -##
|
||||
|
||||
|
||||
def confirm():
|
||||
|
@ -20,7 +21,7 @@ def confirm():
|
|||
|
||||
|
||||
if confirm():
|
||||
sys.exit(0)
|
||||
sys.exit()
|
||||
else:
|
||||
sys.exit(1)
|
||||
quit_make()
|
||||
#% endblock %#
|
||||
|
|
82
src/help.py
82
src/help.py
|
@ -7,6 +7,7 @@ import os
|
|||
import re
|
||||
|
||||
##- '$(ansi_py)' -##
|
||||
##- '$(quit_make_py)' -##
|
||||
|
||||
MaxLens = namedtuple("MaxLens", "goal msg")
|
||||
|
||||
|
@ -14,6 +15,7 @@ MaxLens = namedtuple("MaxLens", "goal msg")
|
|||
pattern = re.compile(
|
||||
r"^## (?P<goal>.*?) \| (?P<msg>.*?)(?:\s?\| args: (?P<msgargs>.*?))?$$|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<rawargs>.*?))?$$"
|
||||
)
|
||||
goal_pattern = re.compile(r"""^(?!#|\t)(.*):.*\n\t""", re.MULTILINE)
|
||||
|
||||
|
||||
def parseargs(argstring):
|
||||
|
@ -35,18 +37,59 @@ def gen_makefile():
|
|||
return makefile
|
||||
|
||||
|
||||
def parse_make(file):
|
||||
def parse_help(file, hidden=False):
|
||||
for line in file.splitlines():
|
||||
match = pattern.search(line)
|
||||
if match:
|
||||
if not os.getenv("SHOW_HIDDEN") and str(
|
||||
match.groupdict().get("goal")
|
||||
).startswith("_"):
|
||||
if (
|
||||
not hidden
|
||||
and not os.getenv("SHOW_HIDDEN")
|
||||
and str(match.groupdict().get("goal")).startswith("_")
|
||||
):
|
||||
pass
|
||||
else:
|
||||
yield {k: v for k, v in match.groupdict().items() if v is not None}
|
||||
|
||||
|
||||
def recipe_help_header(goal):
|
||||
item = [
|
||||
i
|
||||
for i in list(parse_help(gen_makefile(), hidden=True))
|
||||
if "goal" in i and goal == i["goal"]
|
||||
]
|
||||
if item:
|
||||
return fmt_goal(
|
||||
item[0]["goal"],
|
||||
item[0]["msg"],
|
||||
len(item[0]["goal"]),
|
||||
item[0].get("msgargs", ""),
|
||||
)
|
||||
else:
|
||||
return f" {ansi.style(goal,'$(GOAL_STYLE)')}:"
|
||||
|
||||
|
||||
def parse_goal(file, goal):
|
||||
goals = goal_pattern.findall(file)
|
||||
matched_goal = [i for i in goals if goal in i.split()]
|
||||
output = []
|
||||
|
||||
if matched_goal:
|
||||
output.append(recipe_help_header(matched_goal[0]))
|
||||
lines = file.splitlines()
|
||||
loc = [n for n, l in enumerate(lines) if l.startswith(f"{matched_goal[0]}:")][0]
|
||||
recipe = []
|
||||
for line in lines[loc + 1 :]:
|
||||
if not line.startswith("\t"):
|
||||
break
|
||||
recipe.append(line)
|
||||
output.append(divider(max((len(l) for l in recipe)) + 5))
|
||||
output.append("\n".join(recipe) + "\n")
|
||||
else:
|
||||
output.append(f"{ansi.b_red}ERROR{ansi.end} Failed to find goal: {goal}")
|
||||
|
||||
return output
|
||||
|
||||
|
||||
def fmt_goal(goal, msg, max_goal_len, argstr):
|
||||
args = parseargs(argstr)
|
||||
goal_style = args.goal_style.strip() if args.goal_style else "$(GOAL_STYLE)"
|
||||
|
@ -58,6 +101,10 @@ def fmt_goal(goal, msg, max_goal_len, argstr):
|
|||
)
|
||||
|
||||
|
||||
def divider(len):
|
||||
return ansi.style(f" {'$(DIVIDER)'*len}", "$(DIVIDER_STYLE)")
|
||||
|
||||
|
||||
def fmt_rawmsg(msg, argstr, maxlens):
|
||||
args = parseargs(argstr)
|
||||
lines = []
|
||||
|
@ -74,12 +121,7 @@ def fmt_rawmsg(msg, argstr, maxlens):
|
|||
else:
|
||||
lines.append(f" {ansi.style(msg,msg_style)}")
|
||||
if args.divider:
|
||||
lines.append(
|
||||
ansi.style(
|
||||
f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}",
|
||||
"$(DIVIDER_STYLE)",
|
||||
)
|
||||
)
|
||||
lines.append(divider(len("$(HELP_SEP)") + sum(maxlens) + 2))
|
||||
if args.whitespace:
|
||||
lines.append("\n")
|
||||
|
||||
|
@ -89,7 +131,7 @@ def fmt_rawmsg(msg, argstr, maxlens):
|
|||
def print_help():
|
||||
lines = [f"""$(USAGE)"""]
|
||||
|
||||
items = list(parse_make(gen_makefile()))
|
||||
items = list(parse_help(gen_makefile()))
|
||||
maxlens = MaxLens(
|
||||
*(max((len(item[x]) for item in items if x in item)) for x in ["goal", "msg"])
|
||||
)
|
||||
|
@ -106,5 +148,21 @@ def print_help():
|
|||
print("\n".join(lines))
|
||||
|
||||
|
||||
print_help()
|
||||
def print_arg_help(help_args):
|
||||
for arg in help_args.split():
|
||||
print(f"{ansi.style('task.mk recipe help','$(HEADER_STYLE)')}\n")
|
||||
print("\n".join(parse_goal(gen_makefile(), arg)))
|
||||
|
||||
|
||||
def main():
|
||||
help_args = os.getenv("HELP_ARGS")
|
||||
if help_args:
|
||||
quit_make()
|
||||
print_arg_help(help_args)
|
||||
else:
|
||||
print_help()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
#% endblock %#
|
||||
|
|
12
src/quit_make.py
Normal file
12
src/quit_make.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
#% extends "py-script.mk" %#
|
||||
#% block name %#quit_make#% endblock %#
|
||||
#% block script %#
|
||||
|
||||
import os, signal
|
||||
|
||||
|
||||
def quit_make():
|
||||
os.kill(os.getppid(), signal.SIGQUIT)
|
||||
|
||||
|
||||
#% endblock %#
|
|
@ -1,24 +1,24 @@
|
|||
# ---- [python/bash script runner] ---- #
|
||||
###-- modified from https://unix.stackexchange.com/a/223093 -###
|
||||
define \n
|
||||
define _newline
|
||||
|
||||
|
||||
endef
|
||||
escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))))
|
||||
escape_printf = $(subst \,\\,$(subst %,%%,$1))
|
||||
create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1)))
|
||||
printline = printf -- "<----------------------------------->\n"
|
||||
_escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))))
|
||||
_escape_printf = $(subst \,\\,$(subst %,%%,$1))
|
||||
_create_string = $(subst $(_newline),\n,$(call _escape_shellstring,$(call _escape_printf,$1)))
|
||||
_printline = printf -- "<----------------------------------->\n"
|
||||
ifdef DEBUG
|
||||
define _debug_runner
|
||||
@printf "$(1) Script:\n";$(printline);
|
||||
@printf "$(call create_string,$(3))\n" | cat -n
|
||||
@$(printline)
|
||||
@printf "$(call create_string,$(3))" | $(2)
|
||||
@printf "$(1) Script:\n";$(_printline);
|
||||
@printf "$(call _create_string,$(3))\n" | cat -n
|
||||
@$(_printline)
|
||||
@$(2) <(printf "$(call _create_string,$(3))")
|
||||
endef
|
||||
py = $(call _debug_runner,Python,python3,$($(1)))
|
||||
tbash = $(call _debug_runner,Bash,bash,$($(1)))
|
||||
else
|
||||
py = @python3 <(printf "$(call create_string,$($(1)))")
|
||||
tbash = @bash <(printf "$(call create_string,$($(1)))")
|
||||
py = @python3 <(printf "$(call _create_string,$($(1)))")
|
||||
tbash = @bash <(printf "$(call _create_string,$($(1)))")
|
||||
endif
|
||||
pysh = python3 <(printf "$(call create_string,$($(1)))")
|
||||
pysh = python3 <(printf "$(call _create_string,$($(1)))")
|
||||
|
|
116
task.mk
116
task.mk
|
@ -1,7 +1,7 @@
|
|||
# }> [github.com/daylinmorgan/task.mk] <{ #
|
||||
# Copyright (c) 2022 Daylin Morgan
|
||||
# MIT License
|
||||
# version: 22.9.19
|
||||
# version: v22.9.19-5-g5f593e3-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.
|
||||
|
@ -18,7 +18,12 @@ HELP_SEP ?= │
|
|||
# python f-string literals
|
||||
EPILOG ?=
|
||||
USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make <recipe>\n
|
||||
# ---- [buitlin recipes] ---- #
|
||||
INHERIT_SHELL ?=
|
||||
# ---- [builtin recipes] ---- #
|
||||
ifeq (help,$(firstword $(MAKECMDGOALS)))
|
||||
HELP_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
|
||||
export HELP_ARGS
|
||||
endif
|
||||
## h, help | show this help
|
||||
.PHONY: help h
|
||||
help h:
|
||||
|
@ -47,29 +52,32 @@ _update-task.mk:
|
|||
$(call tprint,{a.b_cyan}Updating task.mk{a.end})
|
||||
curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk
|
||||
export MAKEFILE_LIST
|
||||
ifndef INHERIT_SHELL
|
||||
SHELL := /bin/bash
|
||||
endif
|
||||
# ---- [python/bash script runner] ---- #
|
||||
define \n
|
||||
define _newline
|
||||
|
||||
|
||||
endef
|
||||
escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))))
|
||||
escape_printf = $(subst \,\\,$(subst %,%%,$1))
|
||||
create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1)))
|
||||
printline = printf -- "<----------------------------------->\n"
|
||||
_escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))))
|
||||
_escape_printf = $(subst \,\\,$(subst %,%%,$1))
|
||||
_create_string = $(subst $(_newline),\n,$(call _escape_shellstring,$(call _escape_printf,$1)))
|
||||
_printline = printf -- "<----------------------------------->\n"
|
||||
ifdef DEBUG
|
||||
define _debug_runner
|
||||
@printf "$(1) Script:\n";$(printline);
|
||||
@printf "$(call create_string,$(3))\n" | cat -n
|
||||
@$(printline)
|
||||
@printf "$(call create_string,$(3))" | $(2)
|
||||
@printf "$(1) Script:\n";$(_printline);
|
||||
@printf "$(call _create_string,$(3))\n" | cat -n
|
||||
@$(_printline)
|
||||
@$(2) <(printf "$(call _create_string,$(3))")
|
||||
endef
|
||||
py = $(call _debug_runner,Python,python3,$($(1)))
|
||||
tbash = $(call _debug_runner,Bash,bash,$($(1)))
|
||||
else
|
||||
py = @python3 <(printf "$(call create_string,$($(1)))")
|
||||
tbash = @bash <(printf "$(call create_string,$($(1)))")
|
||||
py = @python3 <(printf "$(call _create_string,$($(1)))")
|
||||
tbash = @bash <(printf "$(call _create_string,$($(1)))")
|
||||
endif
|
||||
pysh = python3 <(printf "$(call create_string,$($(1)))")
|
||||
pysh = python3 <(printf "$(call _create_string,$($(1)))")
|
||||
# ---- [python scripts] ---- #
|
||||
define help_py
|
||||
import argparse
|
||||
|
@ -77,10 +85,12 @@ from collections import namedtuple
|
|||
import os
|
||||
import re
|
||||
$(ansi_py)
|
||||
$(quit_make_py)
|
||||
MaxLens = namedtuple("MaxLens", "goal msg")
|
||||
pattern = re.compile(
|
||||
r"^## (?P<goal>.*?) \| (?P<msg>.*?)(?:\s?\| args: (?P<msgargs>.*?))?$$|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<rawargs>.*?))?$$"
|
||||
)
|
||||
goal_pattern = re.compile(r"""^(?!#|\t)(.*):.*\n\t""", re.MULTILINE)
|
||||
def parseargs(argstring):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--align")
|
||||
|
@ -96,16 +106,51 @@ def gen_makefile():
|
|||
with open(file, "r") as f:
|
||||
makefile += f.read() + "\n\n"
|
||||
return makefile
|
||||
def parse_make(file):
|
||||
def parse_help(file, hidden=False):
|
||||
for line in file.splitlines():
|
||||
match = pattern.search(line)
|
||||
if match:
|
||||
if not os.getenv("SHOW_HIDDEN") and str(
|
||||
match.groupdict().get("goal")
|
||||
).startswith("_"):
|
||||
if (
|
||||
not hidden
|
||||
and not os.getenv("SHOW_HIDDEN")
|
||||
and str(match.groupdict().get("goal")).startswith("_")
|
||||
):
|
||||
pass
|
||||
else:
|
||||
yield {k: v for k, v in match.groupdict().items() if v is not None}
|
||||
def recipe_help_header(goal):
|
||||
item = [
|
||||
i
|
||||
for i in list(parse_help(gen_makefile(), hidden=True))
|
||||
if "goal" in i and goal == i["goal"]
|
||||
]
|
||||
if item:
|
||||
return fmt_goal(
|
||||
item[0]["goal"],
|
||||
item[0]["msg"],
|
||||
len(item[0]["goal"]),
|
||||
item[0].get("msgargs", ""),
|
||||
)
|
||||
else:
|
||||
return f" {ansi.style(goal,'$(GOAL_STYLE)')}:"
|
||||
def parse_goal(file, goal):
|
||||
goals = goal_pattern.findall(file)
|
||||
matched_goal = [i for i in goals if goal in i.split()]
|
||||
output = []
|
||||
if matched_goal:
|
||||
output.append(recipe_help_header(matched_goal[0]))
|
||||
lines = file.splitlines()
|
||||
loc = [n for n, l in enumerate(lines) if l.startswith(f"{matched_goal[0]}:")][0]
|
||||
recipe = []
|
||||
for line in lines[loc + 1 :]:
|
||||
if not line.startswith("\t"):
|
||||
break
|
||||
recipe.append(line)
|
||||
output.append(divider(max((len(l) for l in recipe)) + 5))
|
||||
output.append("\n".join(recipe) + "\n")
|
||||
else:
|
||||
output.append(f"{ansi.b_red}ERROR{ansi.end} Failed to find goal: {goal}")
|
||||
return output
|
||||
def fmt_goal(goal, msg, max_goal_len, argstr):
|
||||
args = parseargs(argstr)
|
||||
goal_style = args.goal_style.strip() if args.goal_style else "$(GOAL_STYLE)"
|
||||
|
@ -115,6 +160,8 @@ def fmt_goal(goal, msg, max_goal_len, argstr):
|
|||
+ f" $(HELP_SEP) "
|
||||
+ ansi.style(msg, msg_style)
|
||||
)
|
||||
def divider(len):
|
||||
return ansi.style(f" {'$(DIVIDER)'*len}", "$(DIVIDER_STYLE)")
|
||||
def fmt_rawmsg(msg, argstr, maxlens):
|
||||
args = parseargs(argstr)
|
||||
lines = []
|
||||
|
@ -131,18 +178,13 @@ def fmt_rawmsg(msg, argstr, maxlens):
|
|||
else:
|
||||
lines.append(f" {ansi.style(msg,msg_style)}")
|
||||
if args.divider:
|
||||
lines.append(
|
||||
ansi.style(
|
||||
f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}",
|
||||
"$(DIVIDER_STYLE)",
|
||||
)
|
||||
)
|
||||
lines.append(divider(len("$(HELP_SEP)") + sum(maxlens) + 2))
|
||||
if args.whitespace:
|
||||
lines.append("\n")
|
||||
return lines
|
||||
def print_help():
|
||||
lines = [f"""$(USAGE)"""]
|
||||
items = list(parse_make(gen_makefile()))
|
||||
items = list(parse_help(gen_makefile()))
|
||||
maxlens = MaxLens(
|
||||
*(max((len(item[x]) for item in items if x in item)) for x in ["goal", "msg"])
|
||||
)
|
||||
|
@ -157,7 +199,19 @@ def print_help():
|
|||
lines.extend(fmt_rawmsg(item["rawmsg"], item.get("rawargs", ""), maxlens))
|
||||
lines.append(f"""$(EPILOG)""")
|
||||
print("\n".join(lines))
|
||||
print_help()
|
||||
def print_arg_help(help_args):
|
||||
for arg in help_args.split():
|
||||
print(f"{ansi.style('task.mk recipe help','$(HEADER_STYLE)')}\n")
|
||||
print("\n".join(parse_goal(gen_makefile(), arg)))
|
||||
def main():
|
||||
help_args = os.getenv("HELP_ARGS")
|
||||
if help_args:
|
||||
quit_make()
|
||||
print_arg_help(help_args)
|
||||
else:
|
||||
print_help()
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
endef
|
||||
define ansi_py
|
||||
import os
|
||||
|
@ -255,6 +309,7 @@ endef
|
|||
define confirm_py
|
||||
import sys
|
||||
$(ansi_py)
|
||||
$(quit_make_py)
|
||||
def confirm():
|
||||
"""
|
||||
Ask user to enter Y or N (case-insensitive).
|
||||
|
@ -266,7 +321,12 @@ def confirm():
|
|||
answer = input(f"""$(2) {a.b_red}[Y/n]{a.end} """).lower()
|
||||
return answer == "y"
|
||||
if confirm():
|
||||
sys.exit(0)
|
||||
sys.exit()
|
||||
else:
|
||||
sys.exit(1)
|
||||
quit_make()
|
||||
endef
|
||||
define quit_make_py
|
||||
import os, signal
|
||||
def quit_make():
|
||||
os.kill(os.getppid(), signal.SIGQUIT)
|
||||
endef
|
||||
|
|
Loading…
Reference in a new issue