CARGO-PKGID(1)

πŸ“¦ version 1.78.0, in ubuntu jammy, ubuntu noble

✨ CARGO-PKGID ✨

okay bestie, welcome to cargo-pkgid(1) πŸ’– this one lives in the General Commands Manual and it's genuinely one of the most underrated little cargo commands. let's get into it πŸŽ€


πŸ’… NAME πŸ’…

cargo-pkgid β€” print a fully qualified package specification ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

cargo pkgid [options] [spec]

that's it. that's the whole vibe. πŸ‘‘


🌸 DESCRIPTION 🌸

so like, give it a spec argument and it prints out the fully qualified package ID specifier for a package or dependency in the current workspace 🫢 and heads up β€” if that spec is ambiguous about which package it means in the dependency graph, this command will throw an error. no cap. 😭 and if you don't give it a spec at all? it just prints the specifier for the local package. easy.

⚠️ real talk: this command requires that a lockfile is available and that dependencies have already been fetched. no lockfile, no vibes.

a package specifier is made of a name, a version, and a source URL 🌈 and here's the cute part: you're allowed to use partial specifiers to succinctly match a specific package β€” as long as it matches only one package. only. one. πŸ’€ this same specifier format is also used elsewhere in Cargo, like cargo-metadata(1) and the JSON messages Cargo emits, docs at https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages.

the format of a spec can be one of these bad boys:

the full specification grammar lives in chapter Package ID Specifications at https://doc.rust-lang.org/cargo/reference/pkgid-spec.html πŸ“š


✨ OPTIONS ✨

πŸŽ€ Package Selection πŸŽ€

  • -p spec, --package spec β€” get the package ID for the given package instead of the current package. slay, you get to pick. πŸ’…

πŸ“ Display Options πŸ“

  • -v, --verbose β€” use verbose output. may be specified twice for "very verbose" output, which includes extra output such as dependency warnings and build script output πŸ‘€ may also be specified with the term.verbose config value at https://doc.rust-lang.org/cargo/reference/config.html.
  • -q, --quiet β€” do not print cargo log messages 🀫 may also be specified with the term.quiet config value at https://doc.rust-lang.org/cargo/reference/config.html.
  • --color when β€” control when colored output is used 🌈 valid values:
    • auto (default): automatically detect if color support is available on the terminal.
    • always: always display colors.
    • never: never display colors.

may also be specified with the term.color config value at https://doc.rust-lang.org/cargo/reference/config.html.

🧚 Manifest Options 🧚

  • --manifest-path path β€” path to the Cargo.toml file. by default, Cargo searches for the Cargo.toml file in the current directory or any parent directory πŸ”
  • --frozen, --locked β€” either of these flags requires that the Cargo.lock file is up-to-date. if the lock file is missing, or it needs to be updated, Cargo will exit with an error 😭 the --frozen flag also prevents Cargo from attempting to access the network to determine if it is out-of-date.

these may be used in environments where you want to assert that the Cargo.lock file is up-to-date (such as a CI build) or want to avoid network access πŸ›‘οΈ

  • --offline β€” prevents Cargo from accessing the network for any reason. without this flag, Cargo will stop with an error if it needs to access the network and the network is not available. with this flag, Cargo will attempt to proceed without the network if possible.
πŸ’€ beware bestie: this may result in different dependency resolution than online mode. Cargo will restrict itself to crates that are downloaded locally, even if there might be a newer version as indicated in the local copy of the index. see the cargo-fetch(1) command to download dependencies before going offline.

may also be specified with the net.offline config value at https://doc.rust-lang.org/cargo/reference/config.html.

πŸ’œ Common Options πŸ’œ

  • +toolchain β€” if Cargo has been installed with rustup, and the first argument to cargo begins with +, it will be interpreted as a rustup toolchain name (such as +stable or +nightly) ⭐ see the rustup documentation at https://rust-lang.github.io/rustup/overrides.html for more information about how toolchain overrides work.
  • --config KEY=VALUE or PATH β€” overrides a Cargo configuration value. the argument should be in TOML syntax of KEY=VALUE, or provided as a path to an extra configuration file. this flag may be specified multiple times πŸ” see the command-line overrides section at https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides for more information.
  • -C PATH β€” changes the current working directory before executing any specified operations. this affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering .cargo/config.toml, for example. this option must appear before the command name, for example cargo -C path/to/my-project build.
πŸŒ™ this option is only available on the nightly channel at https://doc.rust-lang.org/book/appendix-07-nightly-rust.html and requires the -Z unstable-options flag to enable (see #10098 at https://github.com/rust-lang/cargo/issues/10098). unstable girlies only πŸ’…
  • -h, --help β€” prints help information. the classic. 🫢
  • -Z flag β€” unstable (nightly-only) flags to Cargo. run cargo -Z help for details. πŸ‘‘

🌈 ENVIRONMENT 🌈

see the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads 🧚


⭐ EXIT STATUS ⭐

  • 0: Cargo succeeded. πŸŽ‰
  • 101: Cargo failed to complete. πŸ’€

πŸ”₯ EXAMPLES πŸ”₯

  1. retrieve package specification for foo package:
cargo pkgid foo
  1. retrieve package specification for version 1.0.0 of foo:
cargo pkgid foo@1.0.0
  1. retrieve package specification for foo from crates.io:
cargo pkgid https://github.com/rust-lang/crates.io-index#foo
  1. retrieve package specification for foo from a local package:
cargo pkgid file:///path/to/local/package#foo

🫢 SEE ALSO 🫢


and that's the whole page bestie!! πŸŽ€ this was CARGO-PKGID(1), hanging out in the General Commands Manual section, and honestly? iconic. go forth and print those fully qualified package specs. periodt. πŸ’–βœ¨

πŸ“¦ where this page comes from