Repository: rust-bitcoin/rust-bitcoin (language: rust)

Issue:
no such command public-api
cargo check-api produces the following error: `error: no such command: public-api`

Is it required to install https://crates.io/crates/public-api?  I tried installing it as a dev dep to units where I'm trying to run the update but I'm still encountering the error.


Discussion / hints:
The error message is not helpful. Because it is a subcommand of `cargo`. You need to install https://crates.io/crates/cargo-public-api
Ideally we would include a function `need_cargo_public_api` here that would check if the user has installed it or not with a `command -v` and then exiting `1` and giving a useful error message.

https://github.com/rust-bitcoin/rust-bitcoin/blob/7977231839a847aad181886240336c2eac7beacc/contrib/check-for-api-changes.sh#L23-L32


Fix patch:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index ff1d58665..451376049 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -157,6 +157,9 @@ running `just check-api`.
 - `primitives`
 - `units`
 
+Check the [API text files](api/README.md) for more information
+on how to install the dependencies and create the text files.
+
 ### Repository maintainers
 
 Pull request merge requirements:
diff --git a/api/README.md b/api/README.md
index 8979cd542..f83f990b1 100644
--- a/api/README.md
+++ b/api/README.md
@@ -6,7 +6,7 @@ enabled. To create these files run `../contrib/check-for-api-changes.sh`:
 Requires `cargo-public-api`, install with:
 
 ```
-cargo +stable install cargo-public-api --locked
+cargo +nightly install cargo-public-api --locked
 ```
 
 ref: https://github.com/enselic/cargo-public-api
diff --git a/contrib/check-for-api-changes.sh b/contrib/check-for-api-changes.sh
index dc305dca0..3bfe41571 100755
--- a/contrib/check-for-api-changes.sh
+++ b/contrib/check-for-api-changes.sh
@@ -22,6 +22,7 @@ export LC_ALL=C
 
 main() {
     need_nightly
+    need_cargo_public_api
 
     generate_api_files "hashes"
     generate_api_files "io"
@@ -81,6 +82,13 @@ need_nightly() {
     fi
 }
 
+need_cargo_public_api() {
+    if command -v cargo-public-api > /dev/null; then
+        return
+    fi
+    err "cargo-public-api is not installed; please run 'cargo +nightly install cargo-public-api --locked'"
+}
+
 err() {
     echo "$1" >&2
     exit 1


Test patch: