The cargo metadata
command returns the metadata for the project in JSON form. Using jq
you can easily extract the details. The following command extracts the version of a package in the project.
cargo metadata --format-version 1 | jq '.packages | map(select(.name == <"package-name">)) | .[0].version'