@@ -55,11 +55,11 @@ execute() {
5555 fi
5656}
5757
58- # Takes the name of a tool and an action. If the action is `tool` it is
58+ # Takes the name of a tool and an optional action. If the action is `tool` it is
5959# ignored. It handles the common case where the tool is invoked as `tool
6060# action`.
6161execute_command () {
62- if [ " $2 " = tool ]; then
62+ if [ " $2 " = tool ] || [ -z " $2 " ] ; then
6363 execute " $1 "
6464 else
6565 execute " $1 $2 "
@@ -159,22 +159,12 @@ try_cargo() {
159159try_meson () {
160160 if [ -f meson.build ]; then
161161 case $ACTION in
162- build)
163- execute " meson compile"
164- exit
165- ;;
166- test)
167- execute " meson test"
168- exit
169- ;;
162+ build) execute_command meson compile ;;
163+ test | tool) execute_command meson " $ACTION " ;;
170164 run)
171165 echo " projectdo does not know how to run a project with Meson."
172166 exit
173167 ;;
174- tool)
175- execute " meson"
176- exit
177- ;;
178168 esac
179169 fi
180170}
@@ -186,16 +176,12 @@ try_cmake() {
186176 case $ACTION in
187177 test)
188178 if [ -f build ]; then
189- execute " cmake --build build --target test"
179+ execute_command cmake " --build build --target test"
190180 else
191- execute " cmake --build . --target test"
181+ execute_command cmake " --build . --target test"
192182 fi
193- exit
194- ;;
195- tool)
196- execute " cmake"
197- exit
198183 ;;
184+ tool) execute_command cmake tool ;;
199185 esac
200186 fi
201187}
@@ -222,22 +208,12 @@ try_cabal() {
222208try_maven () {
223209 if [ -f pom.xml ]; then
224210 case $ACTION in
225- build)
226- execute " mvn compile"
227- exit
228- ;;
229- test)
230- execute " mvn test"
231- exit
232- ;;
211+ build) execute_command mvn compile ;;
233212 run)
234213 echo " projectdo does not know how to run a project with Maven."
235214 exit
236215 ;;
237- tool)
238- execute " mvn"
239- exit
240- ;;
216+ test | tool) execute_command mvn " $ACTION " ;;
241217 esac
242218 fi
243219}
@@ -303,11 +279,9 @@ try_makefile() {
303279 elif [ " $ACTION " = test ]; then
304280 # Let's see if the makefile contains a test or check target
305281 if has_make_target " test" ; then
306- execute " make test"
307- exit
282+ execute_command make test
308283 elif has_make_target " check" ; then
309- execute " make check"
310- exit
284+ execute_command make check
311285 fi
312286 fi
313287 fi
@@ -318,10 +292,9 @@ try_makefile() {
318292
319293try_nix_flake () {
320294 if [ -f flake.nix ]; then
321- has_command_or_error nix-build flake.nix nix
295+ has_command_or_error nix flake.nix nix
322296 if [ " $ACTION " = test ]; then
323- execute " nix flake check"
324- exit
297+ execute_command nix " flake check"
325298 else
326299 execute_command nix " $ACTION "
327300 fi
@@ -334,16 +307,9 @@ try_nix_flake() {
334307try_nix_package () {
335308 if [ -f default.nix ]; then
336309 has_command_or_error nix-build default.nix nix
337- case $ACTION in
338- build)
339- execute " nix-build"
340- exit
341- ;;
342- tool)
343- execute " nix-build"
344- exit
345- ;;
346- esac
310+ if [ " $ACTION " = test ] || [ " $ACTION " = tool ]; then
311+ execute_command nix-build
312+ fi
347313 fi
348314 return 1
349315}
@@ -354,24 +320,12 @@ try_python() {
354320 if [ -f pyproject.toml ]; then
355321 if grep -q -m 1 " ^\[tool.poetry\]$" pyproject.toml; then
356322 case $ACTION in
357- build)
358- execute " poetry build"
359- exit
360- ;;
361- test)
362- # TODO: There are other Python test frameworks, it would be nice to
363- # detect and run the right one.
364- execute " poetry run pytest"
365- exit
366- ;;
323+ build | tool) execute_command poetry " $ACTION " ;;
324+ test) execute_command poetry " run pytest" ;;
367325 run)
368326 echo " projectdo does not know how to run a project with Poetry."
369327 exit
370328 ;;
371- tool)
372- execute " poetry"
373- exit
374- ;;
375329 esac
376330 else
377331 if [ -f uv.lock ]; then
@@ -381,17 +335,10 @@ try_python() {
381335 exit
382336 ;;
383337 test)
384- echo " projectdo does not know how to run a project with uv."
385- exit
386- ;;
387- run)
388- execute " uv run"
389- exit
390- ;;
391- tool)
392- execute " uv"
338+ echo " projectdo does not know how to test a project with uv."
393339 exit
394340 ;;
341+ run | tool) execute_command uv " $ACTION " ;;
395342 esac
396343 else
397344 echo " Found a pyproject.toml file but projectdo is not sure how to run it."
@@ -434,14 +381,8 @@ try_go() {
434381try_latex () {
435382 if [ -f Tectonic.toml ]; then
436383 case $ACTION in
437- build)
438- execute " tectonic -X build"
439- exit
440- ;;
441- tool)
442- execute " tectonic"
443- exit
444- ;;
384+ build) execute_command tectonic " -X build" ;;
385+ tool) execute_command tectonic ;;
445386 esac
446387 fi
447388}
@@ -459,17 +400,14 @@ try_dotnet() {
459400try_dune () {
460401 if [ -f dune-project ]; then
461402 case $ACTION in
462- build)
463- execute_command dune build
464- ;;
465403 test)
466404 execute_command dune runtest
467405 ;;
468406 run)
469407 execute_command dune exec
470408 ;;
471- tool)
472- execute_command dune tool
409+ build | tool)
410+ execute_command dune " $ACTION "
473411 ;;
474412 esac
475413 fi
0 commit comments