From 0f8bfab71fcb7e1d31f4dbf84f2534b68dccbb7d Mon Sep 17 00:00:00 2001 From: xerxes2 Date: Wed, 22 May 2024 21:59:54 +1000 Subject: [PATCH 1/2] feat: Add .NET support for project build and execution The code changes introduce support for building and executing .NET projects. The `try_dotnet()` function is added to detect the presence of .csproj, .fsproj, or .sln files and execute the appropriate dotnet command. This allows users to build, run, and test C# and F# projects using the `dotnet build`, `dotnet run`, and `dotnet test` commands respectively. --- README.md | 3 +- man/projectdo.1 | 183 +++++++++++++++----------------- man/projectdo.1.md | 67 ++++++------ projectdo | 9 ++ run-tests.sh | 45 ++++++++ tests/dotnet-csproj/test.csproj | 0 tests/dotnet-fsproj/test.fsproj | 0 tests/dotnet-sln/test.sln | 0 8 files changed, 177 insertions(+), 130 deletions(-) create mode 100644 tests/dotnet-csproj/test.csproj create mode 100644 tests/dotnet-fsproj/test.fsproj create mode 100644 tests/dotnet-sln/test.sln diff --git a/README.md b/README.md index 6e556fe..9cb9eda 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Context-aware single-letter project commands to speed up your command-line workf https://user-images.githubusercontent.com/521604/231857437-12c14aff-585d-4817-8f44-59b40ecc32e0.mov * **Supports 10+ build and project tools** – CMake, Cabal, Cargo, Go, - Leiningen, Mage, Maven, Meson, Poetry, Stack, Tectonic, make, npm, and yarn. + Leiningen, Mage, Maven, Meson, Poetry, Stack, Tectonic, make, npm, yarn and .NET. [More details](#supported-tools-and-languages). * **Portable** – Dependency free portable POSIX shell script. Supports Linux, macOS, WSL, etc. @@ -186,5 +186,6 @@ request. | Mage | Go | `magefile.go` with a `test`/`check` target | `mage test/check` | | Go | Go | `go.mod` | `go test` | | Tectonic | LaTeX | `Tectonic.toml` | `tectonic -X build` | +| .NET | C# and F# | `*.csproj`, `*.fsproj` or `*.sln` | `dotnet build`
`dotnet run`
`dotnet test` | | Shell script | Any | `build.sh` | `sh -c build.sh` | diff --git a/man/projectdo.1 b/man/projectdo.1 index 8e8955e..a7ed9a2 100644 --- a/man/projectdo.1 +++ b/man/projectdo.1 @@ -1,31 +1,13 @@ '\" t -.\" Automatically generated by Pandoc 3.0.1 +.\" Automatically generated by Pandoc 3.1.13 .\" -.\" Define V font for inline verbatim, using C font in formats -.\" that render this, and otherwise B font. -.ie "\f[CB]x\f[]"x" \{\ -. ftr V B -. ftr VI BI -. ftr VB B -. ftr VBI BI -.\} -.el \{\ -. ftr V CR -. ftr VI CI -. ftr VB CB -. ftr VBI CBI -.\} .TH "projectdo" "1" "April 24, 2024" "projectdo 0.2.2" "User Manual" -.hy .SH NAME -.PP -projectdo - build, run, test and more with ease +projectdo \- build, run, test and more with ease .SH SYNOPSIS -.PP \f[B]projectdo\f[R] [\f[I]OPTION\f[R]] [\f[I]ACTIONS\f[R]]\&... .SH DESCRIPTION -.PP -projectdo is a command-line program hat executes project actions (such +projectdo is a command\-line program hat executes project actions (such as build, .PD 0 .P @@ -53,16 +35,16 @@ package.json file is found. .SH OPTIONS .TP -\f[B]-h, \f[VB]--\f[B]help\f[R] +\f[B]\-h, \f[CB]\-\-\f[B]help\f[R] display help message .TP -\f[B]-n, -d, \f[VB]--\f[B]dry-run\f[R] -do not execute any commands with side-effects +\f[B]\-n, \-d, \f[CB]\-\-\f[B]dry\-run\f[R] +do not execute any commands with side\-effects .TP -\f[B]-q, \f[VB]--\f[B]quiet\f[R] +\f[B]\-q, \f[CB]\-\-\f[B]quiet\f[R] do not print commands as they are about to be executed .TP -\f[B]-v, \f[VB]--\f[B]version\f[R] +\f[B]\-v, \f[CB]\-\-\f[B]version\f[R] prints installed projectdo version. .SH ACTIONS .TP @@ -78,17 +60,15 @@ test the project in working directory \f[B]tool\f[R] Invoke the guessed tool for the current project .SH TOOL ARGUMENTS -.PP Any arguments following [action] are passed along to the invoked tool. .SH SHELL INTEGRATION .SS FISH -.PP projectdo ships with a plugin for the Fish shell. The plugin includes .PD 0 .P .PD -auto-completion and functions for use with Fish\[cq]s abbreviation +auto\-completion and functions for use with Fish\[cq]s abbreviation feature. .PP The Fish plugin can be installed manually or with Fisher (fish plugin @@ -96,7 +76,7 @@ manager): .PD 0 .P .PD -\f[V]fisher install paldepind/projectdo\f[R] +\f[CR]fisher install paldepind/projectdo\f[R] .PP The plugin exposes four shell functions that should be configured with .PD 0 @@ -105,39 +85,34 @@ The plugin exposes four shell functions that should be configured with abbreviations as desired. For instance: .IP -.nf -\f[C] -abbr -a b --function projectdo_build -abbr -a r --function projectdo_run -abbr -a t --function projectdo_test -abbr -a p --function projectdo_tool -\f[R] -.fi +.EX +abbr \-a b \-\-function projectdo_build +abbr \-a r \-\-function projectdo_run +abbr \-a t \-\-function projectdo_test +abbr \-a p \-\-function projectdo_tool +.EE .PP -With the above \f[V]t\f[R] will expand to \f[V]cargo test\f[R], -\f[V]p\f[R] will expand to \f[V]cargo\f[R], etc. +With the above \f[CR]t\f[R] will expand to \f[CR]cargo test\f[R], +\f[CR]p\f[R] will expand to \f[CR]cargo\f[R], etc. .PD 0 .P .PD depending on the project. .SS BASH + OTHERS -.PP projectdo can be configured with shell aliases in any shell. For instance: .IP -.nf -\f[C] +.EX alias t=\[aq]projectdo test\[aq] alias r=\[aq]projectdo run\[aq] alias b=\[aq]projectdo build\[aq] alias p=\[aq]projectdo tool\[aq] -\f[R] -.fi +.EE .SH SUPPORTED TOOLS AND LANGUAGES .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ Tool T}@T{ @@ -152,232 +127,246 @@ _ .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ Cargo T}@T{ Rust T}@T{ -\f[V]Cargo.toml\f[R] +\f[CR]Cargo.toml\f[R] T}@T{ -\f[V]cargo build\f[R], \f[V]cargo run\f[R], \f[V]cargo test\f[R] +\f[CR]cargo build\f[R], \f[CR]cargo run\f[R], \f[CR]cargo test\f[R] T} _ .TE .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ Poetry T}@T{ Python T}@T{ -\f[V]pyproject.toml\f[R] +\f[CR]pyproject.toml\f[R] T}@T{ -\f[V]poetry build\f[R], \f[V]poetry run pytest\f[R] +\f[CR]poetry build\f[R], \f[CR]poetry run pytest\f[R] T} _ .TE .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ CMake T}@T{ -C, C++ and Obj-C +C, C++ and Obj\-C T}@T{ -\f[V]CMakeLists.txt\f[R] +\f[CR]CMakeLists.txt\f[R] T}@T{ -\f[V]cmake --build . --target test\f[R] +\f[CR]cmake \-\-build . \-\-target test\f[R] T} _ .TE .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ Meson T}@T{ C, C++, etc. T}@T{ -\f[V]meson.build\f[R] +\f[CR]meson.build\f[R] T}@T{ -\f[V]meson compile\f[R], \f[V]meson test\f[R] +\f[CR]meson compile\f[R], \f[CR]meson test\f[R] T} _ .TE .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ npm T}@T{ JavaScript, etc. T}@T{ -\f[V]package.json\f[R] +\f[CR]package.json\f[R] T}@T{ -\f[V]npm build\f[R], \f[V]npm start\f[R], \f[V]npm test\f[R] +\f[CR]npm build\f[R], \f[CR]npm start\f[R], \f[CR]npm test\f[R] T} _ .TE .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ yarn T}@T{ JavaScript, etc. T}@T{ -\f[V]package.json\f[R], \f[V]yarn.lock\f[R] +\f[CR]package.json\f[R], \f[CR]yarn.lock\f[R] T}@T{ -\f[V]yarn build\f[R], \f[V]yarn start\f[R], \f[V]yarn test\f[R] +\f[CR]yarn build\f[R], \f[CR]yarn start\f[R], \f[CR]yarn test\f[R] T} _ .TE .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ Maven T}@T{ Java, etc. T}@T{ -\f[V]pom.xml\f[R] +\f[CR]pom.xml\f[R] T}@T{ -\f[V]mvn compile\f[R], \f[V]mvn test\f[R] +\f[CR]mvn compile\f[R], \f[CR]mvn test\f[R] T} _ .TE .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ Leiningen T}@T{ Clojure T}@T{ -\f[V]project.clj\f[R] +\f[CR]project.clj\f[R] T}@T{ -\f[V]lein test\f[R] +\f[CR]lein test\f[R] T} _ .TE .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ Cabal T}@T{ Haskell T}@T{ -\f[V]*.cabal\f[R] +\f[CR]*.cabal\f[R] T}@T{ -\f[V]cabal build\f[R], \f[V]cabal run\f[R], \f[V]cabal test\f[R] +\f[CR]cabal build\f[R], \f[CR]cabal run\f[R], \f[CR]cabal test\f[R] T} _ .TE .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ Stack T}@T{ Haskell T}@T{ -\f[V]stack.yaml\f[R] +\f[CR]stack.yaml\f[R] T}@T{ -\f[V]stack build\f[R], \f[V]stack run\f[R], \f[V]stack test\f[R] +\f[CR]stack build\f[R], \f[CR]stack run\f[R], \f[CR]stack test\f[R] T} _ .TE .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ make T}@T{ Any T}@T{ -\f[V]Makefile\f[R] +\f[CR]Makefile\f[R] T}@T{ -\f[V]make\f[R], \f[V]make test/check\f[R] +\f[CR]make\f[R], \f[CR]make test/check\f[R] T} _ .TE .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ Mage T}@T{ Go T}@T{ -\f[V]magefile.go + test/check target\f[R] +\f[CR]magefile.go + test/check target\f[R] T}@T{ -\f[V]mage test/check\f[R] +\f[CR]mage test/check\f[R] T} _ .TE .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ Go T}@T{ Go T}@T{ -\f[V]go.mod\f[R] +\f[CR]go.mod\f[R] T}@T{ -\f[V]go test\f[R] +\f[CR]go test\f[R] T} _ .TE .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ Tectonic T}@T{ LaTeX T}@T{ -\f[V]Tectonic.toml\f[R] +\f[CR]Tectonic.toml\f[R] +T}@T{ +\f[CR]tectonic \-X build\f[R] +T} +_ +.TE +.PP +.TS +tab(@); +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). +T{ +\&.NET +T}@T{ +C# and F# +T}@T{ +\f[CR]*.csproj\f[R], \f[CR]*.fsproj\f[R] or \f[CR]*.sln\f[R] T}@T{ -\f[V]tectonic -X build\f[R] +\f[CR]dotnet build\f[R], \f[CR]dotnet run\f[R], \f[CR]dotnet test\f[R] T} _ .TE .PP .TS tab(@); -lw(8.7n) lw(11.2n) lw(24.2n) lw(26.0n). +lw(8.4n) lw(10.9n) lw(23.5n) lw(27.2n). T{ Shell script T}@T{ Any T}@T{ -\f[V]build.sh\f[R] +\f[CR]build.sh\f[R] T}@T{ -\f[V]sh -c build.sh\f[R] +\f[CR]sh \-c build.sh\f[R] T} _ .TE .SH AUTHOR -.PP -Written by \f[V]K_Lar\f[R]. +Written by \f[CR]K_Lar\f[R]. .SH REPORTING BUGS -.PP -Report any bugs you might find here: - +Report any bugs you might find here: \c +.UR https://github.com/paldepind/projectdo/issues +.UE \c diff --git a/man/projectdo.1.md b/man/projectdo.1.md index f788e69..cd51cd1 100644 --- a/man/projectdo.1.md +++ b/man/projectdo.1.md @@ -91,53 +91,56 @@ alias p='projectdo tool' # SUPPORTED TOOLS AND LANGUAGES -| Tool | Language | Detected by | Commands | -|--------------|------------------|---------------------------------------|------------------------------------------| +| Tool | Language | Detected by | Commands | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| Cargo | Rust | `Cargo.toml` | `cargo build`, `cargo run`, `cargo test` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| Cargo | Rust | `Cargo.toml` | `cargo build`, `cargo run`, `cargo test` | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| Poetry | Python | `pyproject.toml` | `poetry build`, `poetry run pytest` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| Poetry | Python | `pyproject.toml` | `poetry build`, `poetry run pytest` | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| CMake | C, C++ and Obj-C | `CMakeLists.txt` | `cmake --build . --target test` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| CMake | C, C++ and Obj-C | `CMakeLists.txt` | `cmake --build . --target test` | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| Meson | C, C++, etc. | `meson.build` | `meson compile`, `meson test` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| Meson | C, C++, etc. | `meson.build` | `meson compile`, `meson test` | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| npm | JavaScript, etc. | `package.json` | `npm build`, `npm start`, `npm test` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| npm | JavaScript, etc. | `package.json` | `npm build`, `npm start`, `npm test` | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| yarn | JavaScript, etc. | `package.json`, `yarn.lock` | `yarn build`, `yarn start`, `yarn test` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| yarn | JavaScript, etc. | `package.json`, `yarn.lock` | `yarn build`, `yarn start`, `yarn test` | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| Maven | Java, etc. | `pom.xml` | `mvn compile`, `mvn test` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| Maven | Java, etc. | `pom.xml` | `mvn compile`, `mvn test` | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| Leiningen | Clojure | `project.clj` | `lein test` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| Leiningen | Clojure | `project.clj` | `lein test` | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| Cabal | Haskell | `*.cabal` | `cabal build`, `cabal run`, `cabal test` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| Cabal | Haskell | `*.cabal` | `cabal build`, `cabal run`, `cabal test` | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| Stack | Haskell | `stack.yaml` | `stack build`, `stack run`, `stack test` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| Stack | Haskell | `stack.yaml` | `stack build`, `stack run`, `stack test` | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| make | Any | `Makefile` | `make`, `make test/check` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| make | Any | `Makefile` | `make`, `make test/check` | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| Mage | Go | `magefile.go + test/check target` | `mage test/check` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| Mage | Go | `magefile.go + test/check target` | `mage test/check` | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| Go | Go | `go.mod` | `go test` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| Go | Go | `go.mod` | `go test` | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| Tectonic | LaTeX | `Tectonic.toml` | `tectonic -X build` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| Tectonic | LaTeX | `Tectonic.toml` | `tectonic -X build` | +|--------------|------------------|---------------------------------------|---------------------------------------------| -| Shell script | Any | `build.sh` | `sh -c build.sh` | -|--------------|------------------|---------------------------------------|------------------------------------------| +| .NET | C# and F# | `*.csproj`, `*.fsproj` or `*.sln` | `dotnet build`, `dotnet run`, `dotnet test` | +|--------------|------------------|---------------------------------------|---------------------------------------------| + +| Shell script | Any | `build.sh` | `sh -c build.sh` | +|--------------|------------------|---------------------------------------|---------------------------------------------| # AUTHOR diff --git a/projectdo b/projectdo index 1eea087..74ea83d 100755 --- a/projectdo +++ b/projectdo @@ -287,6 +287,14 @@ try_latex() { fi } +# .NET + +try_dotnet() { + if [ -f *.csproj ] || [ -f *.fsproj ] || [ -f *.sln ]; then + execute_command dotnet "$ACTION" + fi +} + # Any / Generic try_build_script() { @@ -313,6 +321,7 @@ detect_and_run() { try_python try_go try_latex + try_dotnet try_build_script } diff --git a/run-tests.sh b/run-tests.sh index ccccf20..b29e184 100644 --- a/run-tests.sh +++ b/run-tests.sh @@ -196,6 +196,51 @@ if describe "meson"; then fi fi +if describe "dotnet csproj"; then + if it "can build with dotnet"; then + do_build_in "dotnet-csproj"; assert + assertEqual "$RUN_RESULT" "dotnet build" + fi + if it "can run with dotnet"; then + do_run_in "dotnet-csproj"; assert + assertEqual "$RUN_RESULT" "dotnet run" + fi + if it "can test with dotnet"; then + do_test_in "dotnet-csproj"; assert + assertEqual "$RUN_RESULT" "dotnet test" + fi +fi + +if describe "dotnet fsproj"; then + if it "can build with dotnet"; then + do_build_in "dotnet-fsproj"; assert + assertEqual "$RUN_RESULT" "dotnet build" + fi + if it "can run with dotnet"; then + do_run_in "dotnet-fsproj"; assert + assertEqual "$RUN_RESULT" "dotnet run" + fi + if it "can test with dotnet"; then + do_test_in "dotnet-fsproj"; assert + assertEqual "$RUN_RESULT" "dotnet test" + fi +fi + +if describe "dotnet sln"; then + if it "can build with dotnet"; then + do_build_in "dotnet-sln"; assert + assertEqual "$RUN_RESULT" "dotnet build" + fi + if it "can run with dotnet"; then + do_run_in "dotnet-sln"; assert + assertEqual "$RUN_RESULT" "dotnet run" + fi + if it "can test with dotnet"; then + do_test_in "dotnet-sln"; assert + assertEqual "$RUN_RESULT" "dotnet test" + fi +fi + if describe "build script"; then if it "can build with build script"; then do_build_in "build_script"; assert diff --git a/tests/dotnet-csproj/test.csproj b/tests/dotnet-csproj/test.csproj new file mode 100644 index 0000000..e69de29 diff --git a/tests/dotnet-fsproj/test.fsproj b/tests/dotnet-fsproj/test.fsproj new file mode 100644 index 0000000..e69de29 diff --git a/tests/dotnet-sln/test.sln b/tests/dotnet-sln/test.sln new file mode 100644 index 0000000..e69de29 From c179babb06d8b48bcd2ddcdb9049dac9034b718a Mon Sep 17 00:00:00 2001 From: xerxes2 Date: Thu, 23 May 2024 20:04:08 +1000 Subject: [PATCH 2/2] fix: misuse of -f --- projectdo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projectdo b/projectdo index 74ea83d..da126e9 100755 --- a/projectdo +++ b/projectdo @@ -290,7 +290,7 @@ try_latex() { # .NET try_dotnet() { - if [ -f *.csproj ] || [ -f *.fsproj ] || [ -f *.sln ]; then + if [ -n "$(find . -maxdepth 1 \( -name '*.csproj' -o -name '*.fsproj' -o -name '*.sln' \) -print -quit)" ]; then execute_command dotnet "$ACTION" fi }