<div dir="ltr">I was opening a new PR to update a Rust dependency today and could not figure out how to update the `cargo.crates` section. Digging through the cargo-fetch portgroup pointed me to <a href="https://github.com/macports/macports-contrib/tree/master/cargo2port/cargo2port.tcl">https://github.com/macports/macports-contrib/tree/master/cargo2port/cargo2port.tcl</a>, which fails to run because the Cargo.lock format appears not to be the same as it was when written.<div><br></div><div>Using toml2json (from the Python remarshal package) and jq, I managed to make a simple bash function that does the same thing, more or less. It *always* prints using the max name / version lengths and it requires that `Cargo.lock` be in the current directory, but these are small prices to pay. This may also be simplified if you have <a href="https://github.com/simonrupf/convert2json">https://github.com/simonrupf/convert2json</a> installed, where I believe you could simply use `tq` (this is not currently available as a port; adding one won't be hard, but feature selection will be tricky because it attempts to install a `yq` binary by default, making it conflict with the yq port).</div><div><br></div><div>cargo2port() {<br>  toml2json Cargo.lock | jq -r $'<br>  def lpad($len; $fill): tostring | ($len - length) as $l | ($fill * $l)[:$l] + .;<br>  def lpad($len): lpad($len; " ");<br>  def rpad($len; $fill): tostring | ($len - length) as $l | . + ($fill * $l)[:$l];<br>  def rpad($len): rpad($len; " ");<br>  .package |<br>    map(select(.checksum != null)) |<br>    (. | max_by(.name | length) | .name | length) as $max_name |<br>    (. | max_by(.version | length) | .version | length) as $max_version |<br>    map("    \(.name | rpad($max_name))  \(.version | lpad($max_version))  \(.checksum)") |<br>    join(" \\\\\n") as $body |<br>    "cargo.crates \\\\\n\($body)"<br>'<br>}<br><div><br></div><div>In any case, I hope this helps anyone else who wants to modify a Rust port.</div><div><br></div><div>-a</div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Austin Ziegler • <a href="mailto:halostatue@gmail.com" target="_blank">halostatue@gmail.com</a> • <a href="mailto:austin@halostatue.ca" target="_blank">austin@halostatue.ca</a><br><a href="http://www.halostatue.ca/" target="_blank">http://www.halostatue.ca/</a> • <a href="http://twitter.com/halostatue" target="_blank">http://twitter.com/halostatue</a></div></div></div>