#
cargo/ops/
cargo_pkgid.rs

    1use crate::core::{PackageIdSpec, PackageIdSpecQuery, Workspace};
    2use crate::ops;
    3use crate::util::CargoResult;
    4
    5pub fn pkgid(ws: &Workspace<'_>, spec: Option<&str>) -> CargoResult<PackageIdSpec> {
    6    let Some(resolve) = ops::load_pkg_lockfile(ws)? else {
    7        anyhow::bail!("a Cargo.lock must exist for this command")
    8    };
    9
    10    let pkgid = match spec {
    11        Some(spec) => PackageIdSpec::query_str(spec, resolve.iter())?,
    12        None => ws.current()?.package_id(),
    13    };
    14    Ok(pkgid.to_spec())
    15}