team icon indicating copy to clipboard operation
team copied to clipboard

Bash-friendly way to query cargo metadata (package version)

Open kornelski opened this issue 7 years ago • 4 comments

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.

kornelski avatar Apr 21 '18 00:04 kornelski

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.

epage avatar Apr 21 '18 02:04 epage

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)

ashutoshrishi avatar Sep 10 '19 06:09 ashutoshrishi