cargo-check.ps1 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env pwsh
  2. # Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  3. # SPDX-License-Identifier: Apache-2.0
  4. # SPDX-License-Identifier: MIT
  5. # note: you can pass in the cargo sub-commands used to check manually.
  6. # allowed commands: check, clippy, fmt, test
  7. # default: clippy, fmt, test
  8. # set the script arguments if none are found
  9. if(-Not $args) {
  10. $args=@("clippy","fmt","test")
  11. }
  12. # exit the script early if the last command returned an error
  13. function check_error {
  14. if($LASTEXITCODE -ne 0 ) {
  15. Exit $LASTEXITCODE
  16. }
  17. }
  18. function run {
  19. $command, $_args = $args
  20. Write-Output "[$command]"
  21. cargo $command --workspace --all-targets --all-features $_args
  22. check_error
  23. }
  24. foreach ($command in $args) {
  25. Switch ($command) {
  26. "check" {
  27. run check
  28. break
  29. }
  30. "test" {
  31. run test
  32. break
  33. }
  34. "clippy" {
  35. run clippy "--" -D warnings
  36. break
  37. }
  38. "fmt" {
  39. Write-Output "[$command] checking formatting"
  40. cargo +nightly fmt "--" --check
  41. check_error
  42. }
  43. default {
  44. Write-Output "[cargo-check.ps1] Unknown cargo sub-command: $command"
  45. Exit 1
  46. }
  47. }
  48. }