cargo-pkgid(1)

NAME

cargo-pkgid - Print a fully qualified package specification

SYNOPSIS

cargo pkgid [options] [spec]

DESCRIPTION

Given a spec argument, print out the fully qualified package ID specifier for a package or dependency in the current workspace. This command will generate an error if spec is ambiguous as to which package it refers to in the dependency graph. If no spec is given, then the specifier for the local package is printed.

This command requires that a lockfile is available and dependencies have been fetched.

A package specifier consists of a name, version, and source URL. You are allowed to use partial specifiers to succinctly match a specific package as long as it matches only one package. The format of a spec can be one of the following:

SPEC StructureExample SPEC
namebitflags
name:versionbitflags:1.0.4
urlhttps://github.com/rust-lang/cargo
url#versionhttps://github.com/rust-lang/cargo#0.33.0
url#namehttps://github.com/rust-lang/crates.io-index#bitflags
url#name:versionhttps://github.com/rust-lang/cargo#crates-io:0.21.0

OPTIONS

Package Selection

-p spec
--package spec
Get the package ID for the given package instead of the current package.

Display Options

-v
--verbose
启用更加详细的输出。可两次使用来显示"非常详细"的输出,其中包含了诸如 依赖警告 以及 构建脚本输出 等额外的输出内容。 也可通过term.verbose指定。 config value.
-q
--quiet
不输出Cargo的日志信息。也可通过term.quiet指定。 config value.
--color when
控制输出内容的颜色。有效取值如下:

  • auto (默认):自动检测终端是否支持带颜色的输出。
  • always:总显示带颜色的输出。
  • never:从不显示带颜色的输出。

也可通过term.color指定。 config value.

Manifest Options

--manifest-path path
用于指定Cargo.toml文件的路径。默认情况下,Cargo会在当前目录或上级目录中寻找Cargo.toml文件。
--frozen
--locked
这两个选项用于保证Cargo.lock文件是最新的。如果该锁文件不存在,或者不是最新的,Cargo 会报错退出。其中--frozen选项会阻止Cargo访问网络以检查锁文件是否是最新的。

这些选项,可用于保证Cargo.lock文件是最新的(比如持续集成的构建过程), 或用于避免联网。

--offline
禁止Cargo访问网络。如果不添加此选项,Cargo在需要访问网络但网络不可用的情况下,会报错 并停止工作。添加此选项后,Cargo会尽可能尝试不使用网络来工作。

注意,在此情况下可能会产生与联网状态下不同的依赖解析(Dependency Resolution)结果。 Cargo只会使用本地已下载的crate,即便本地的索引副本中表明可能有新版本crate。在离线前下载 所需依赖的方法,参见 cargo-fetch(1)

也可以通过 net.offline config value指定。

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 for more information about how toolchain overrides work.
-h
--help
Prints help information.
-Z flag
Unstable (nightly-only) flags to Cargo. Run cargo -Z help for details.

环境

关于Cargo所读取的环境变量,可参见the reference

退出状态

  • 0: Cargo命令执行成功
  • 101: Cargo命令未能完成.

EXAMPLES

  1. Retrieve package specification for foo package:

    cargo pkgid foo
    
  2. Retrieve package specification for version 1.0.0 of foo:

    cargo pkgid foo:1.0.0
    
  3. Retrieve package specification for foo from crates.io:

    cargo pkgid https://github.com/rust-lang/crates.io-index#foo
    
  4. 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)