Skip to content

Commit 22c62ff

Browse files
committed
implement simple make-based command arg handling
1 parent 8ea73f0 commit 22c62ff

File tree

3 files changed

+47
-30
lines changed

3 files changed

+47
-30
lines changed

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.PHONY: _tasks
2+
_tasks: .tasks
3+
4+
.PHONY: s start
5+
s start: end # start app
6+
@echo "start app"
7+
@make frontend
8+
9+
.PHONY: e end
10+
e end: # stop app
11+
@echo "stop app"
12+
13+
.PHONY: t test
14+
t test: # run all tests or specific test [vars: name='all']
15+
@[[ -n "$(name)" ]] && echo "run test $(name)" || echo "run test all"
16+
17+
.PHONY: r repl
18+
r repl: # start shell in project environment [vars: env='']
19+
@echo "start shell in project environment: $(env)"
20+
21+
.PHONY: .tasks
22+
.tasks:
23+
@grep -E "^[a-zA-Z0-9 _-]+:[a-zA-Z0-9 _-]*#" $(MAKEFILE_LIST) \
24+
| sed -Ee 's/^/\t/' -e "s/[ ]*:[a-zA-Z0-9 _-]*#[ ]*/ · /"

Runfile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
s start: end#start app
1+
s start: end # start app
22
echo "start app"
33
run frontend
44

5-
e end: #stop app
5+
e end: # stop app
66
echo "stop app"
77

8-
f frontend:#open frontend app
9-
echo "open frontend app"
8+
t test: # run all tests or specific test [vars: name='all']
9+
[[ -n "$(name)" ]] && echo "run test $(name)" || echo "run test all"
1010

11-
b backend:#attach to backend server
12-
echo "attach to backend server"
13-
14-
r repl :# start shell
15-
echo "start shell"
11+
r repl: # start shell in project environment [vars: env='']
12+
echo "start shell in project environment: $(env)"

runfile.sh

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@ echo "start app"
1818
run frontend
1919
e end: # stop app
2020
echo "stop app"
21-
f frontend: # open frontend app
22-
run start
23-
echo "open frontend app"
24-
b backend: # attach to backend server
25-
run start
26-
echo "attach to backend server"
27-
r repl: # start shell in project environment
28-
echo "start shell environment"
21+
t test: # run all tests or specific test [vars: name='all']
22+
[[ -n "\$(name)" ]] && echo "run test \$(name)" || echo "run test all"
23+
r repl: # start shell in project environment [vars: env='']
24+
echo "start shell in project environment: \$(env)"
2925
EOF
3026
else
3127
cat <<EOF> Runfile
@@ -36,14 +32,11 @@ s start: end # start app
3632
e end: # stop app
3733
echo "stop app"
3834
39-
f frontend: # open frontend app
40-
echo "open frontend app"
35+
t test: # run all tests or specific test [vars: name='all']
36+
[[ -n "\$(name)" ]] && echo "run test \$(name)" || echo "run test all"
4137
42-
b backend: # attach to backend server
43-
echo "attach to backend server"
44-
45-
r repl: # start shell
46-
echo "start shell"
38+
r repl: # start shell in project environment [vars: env='']
39+
echo "start shell in project environment: \$(env)"
4740
EOF
4841
fi
4942
}
@@ -107,7 +100,7 @@ function cd-to-nearest-file() { local lower='' upper='' title=''
107100
}
108101
109102
function main() ( set -euo pipefail
110-
local mf='' at='' ws='' arg='' args=() cmd="" rewrite=""
103+
local mf='' at='' ws='' rewrite="" cmd="" arg='' make_args=() cmd_args=()
111104
112105
# Handle various optional actions:
113106
[[ " $* " == *' --create-runfile '* || " $* " == *' --overwrite-runfile '* ]] && \
@@ -161,8 +154,11 @@ function main() ( set -euo pipefail
161154
if [[ -z "${cmd}" ]]
162155
then
163156
cmd="${arg}"
157+
elif [[ " ${arg}" == *' -' ]]
158+
then
159+
make_args+=( "${arg}" )
164160
else
165-
args+=( "${arg}" )
161+
cmd_args+=( "${arg}" )
166162
fi
167163
fi
168164
done
@@ -220,14 +216,14 @@ EOF
220216
# Main Path : Invoke make with generated makefile and all other arguments.
221217
if [[ " $* " == *' --dry-run-command '* ]]
222218
then
223-
make --makefile "${mf}" --dry-run "${cmd}"
219+
make_args+=( --dry-run "${cmd}" )
224220
elif [[ -n "${cmd}" ]]
225221
then
226-
make --makefile "${mf}" "${cmd}"
227-
else
228-
make --makefile "${mf}"
222+
make_args+=( "${cmd}" )
229223
fi
230224
225+
make --makefile "${mf}" "${make_args[@]}" -- "${cmd_args[@]}"
226+
231227
# Clean up temporary Makefile and exit with success:
232228
rm "${mf}"
233229
exit 0

0 commit comments

Comments
 (0)