CARGO-PKGID(1)

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

🌸 CARGO-PKGID(1) 🌸

okay bestie, welcome to the General Commands Manual page for cargo-pkgid β€” yes that's the manual name, it's giving very official, we love that for us. sit down, grab a strawberry something, and let's get into it πŸ’–


✨ NAME ✨

cargo-pkgid β€” print a fully qualified package specification πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

cargo pkgid [options] [spec]

πŸ’… DESCRIPTION πŸ’…

okay so, the way this works: you hand it a spec argument, and it prints out the fully qualified package ID specifier for a package or a dependency that lives in your current workspace. ✨

heads up though β€” if spec is ambiguous about which package it's referring to in the dependency graph, this command will straight up generate an error. no cap. 😭

and if you give it no spec at all? then it prints the specifier for the local package. cute, right?

also important: this command requires that a lockfile is available and that your dependencies have already been fetched. fr fr, don't skip that step.

so a package specifier is made up of a name, a version, and a source URL. and here's the slay part β€” you're allowed to use partial specifiers to succinctly match a specific package, as long as it matches only one package. this same specifier is used by other parts of Cargo too, like cargo-metadata(1) and the JSON messages that Cargo emits (https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages). iykyk πŸ’œ

the format of a spec can be one of these:

and the full specification grammar lives in the chapter Package ID Specifications over at https://doc.rust-lang.org/cargo/reference/pkgid-spec.html. go read it, it's iconic 🧚


πŸ‘‘ OPTIONS πŸ‘‘

πŸŽ€ Package Selection

  • -p spec, --package spec β€” get the package ID for the given package instead of the current package.

🌈 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 (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 (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 (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.
  • --locked β€” asserts that the exact same dependencies and versions are used as when the existing Cargo.lock file was originally generated. Cargo will exit with an error when either of these scenarios arises:
    • the lock file is missing.
    • Cargo attempted to change the lock file due to a different dependency resolution.

it may be used in environments where deterministic builds are desired, such as in CI pipelines. very "i need this to be the same every single time" energy ✨

  • --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 (https://doc.rust-lang.org/cargo/reference/config.html).

  • --frozen β€” equivalent to specifying both --locked and --offline. two for one, we love a bundle 🫢
  • --lockfile-path PATH β€” changes the path of the lockfile from the default (<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock (e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). note that providing --lockfile-path will ignore the existing lockfile at the default path, and instead will either use the lockfile from PATH, or write a new lockfile into the provided PATH if it doesn't exist. this flag can be used to run most commands in read-only directories, writing the lockfile into the provided PATH.
this option is only available on the nightly channel (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the -Z unstable-options flag to enable (see #14421, https://github.com/rust-lang/cargo/issues/14421).

πŸ’œ 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 (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 (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 (https://doc.rust-lang.org/book/appendix-07-nightly-rust.html) and requires the -Z unstable-options flag to enable (see #10098, https://github.com/rust-lang/cargo/issues/10098).
  • -h, --help β€” prints help information.
  • -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 the 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 πŸ’–

cargo(1), cargo-generate-lockfile(1), cargo-metadata(1), Package ID Specifications (https://doc.rust-lang.org/cargo/reference/pkgid-spec.html), JSON messages (https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages)


and that's the whole page bestie, CARGO-PKGID(1) from the General Commands Manual, signed off the exact same way it came in β€” CARGO-PKGID(1) 🫢✨

πŸ“¦ where this page comes from