Because I keep having to look at the jq manual, here are some of my common examples for easy reference.
Some of these commands make use of my jq modules, assuming the repo is cloned to a heaths directory in the default or specified module root e.g., ~/.jq/heaths.
Select all instances of a dependency from cargo metadata in a workspace and put them into a JSON array:
# Alternatively could put the whole first jq expression into square brackets but I find this easier to modify the expression.
cargo metadata --format-version 1 | jq '.packages[] as $package | $package.dependencies[] | select(.name == "azure_core") | {name: .name, req: .req, package: $package.name}' | jq -sPublish all packages in a workspace (pass -n to cargo publish for a dry run):
// Any dependencies like azure_core should be listed before dependents.
for p in $(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name | startswith("azure")) | .name'); do
cargo publish --package $p
doneUsing my version module, you can get the latest crate info from https://crates.io:
curl -s https://index.crates.io/az/ur/azure_core | jq -s 'include "heaths/version"; . | max_by(.vers | toversion)'Or just to get the version number:
curl -s https://index.crates.io/az/ur/azure_core | jq -rs 'include "heaths/version"; [.[].vers] | max_by(toversion)'
Most recent version can be found at https://hackmd.io/@heaths/jq