Bash-friendly way to query cargo metadata (package version)
Related to #8
I package my apps with a bash script sort of like this:
cargo build --release
tar cjf app-$VERSION.tar.gz target/release/app
rsync etc.
The problematic part is $VERSION. I would like to read the version from Cargo.toml, but can't without string manipulation in bash (yuck!)
I'd be great if there was something like cargo metadata --query package.version that outputs nothing by the given Cargo.toml key.
Is your need as much about querying the version or just streamlining creating tarballs of your application?
I'm working on https://github.com/crate-ci/meta/issues/1 which should help with tarballing. My goal is to have a prototype of cargo-tarball in the next two weeks.
Not too advanced at using awk but this works for me:
awk -F ' = ' '$1 ~ /version/ { gsub(/[\"]/, "", $2); printf("%s",$2) }' Cargo.toml
I use it in a Makefile as:
PKG_VERSION = $(shell awk -F ' = ' '$$1 ~ /version/ { gsub(/[\"]/, "", $$2); printf("%s",$$2) }' Cargo.toml)