crate-version.sh 475 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env bash
  2. #
  3. # Outputs the current crate version from a given Cargo.toml
  4. #
  5. set -e
  6. Cargo_toml=$1
  7. [[ -n $Cargo_toml ]] || {
  8. echo "Usage: $0 path/to/Cargo.toml"
  9. exit 0
  10. }
  11. [[ -r $Cargo_toml ]] || {
  12. echo "Error: unable to read $Cargo_toml"
  13. exit 1
  14. }
  15. while read -r name equals value _; do
  16. if [[ $name = version && $equals = = ]]; then
  17. echo "${value//\"/}"
  18. exit 0
  19. fi
  20. done < <(cat "$Cargo_toml")
  21. echo Unable to locate version in Cargo.toml 1>&2
  22. exit 1