diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 726a334d..30be32f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,22 +92,23 @@ jobs: RUSTFLAGS="-C instrument-coverage" cargo build echo "$PWD/target/debug" >> $GITHUB_PATH - - name: run integrations - run: | - pkgx --help - pkgx --version - pkgx +git - pkgx +git --json - pkgx +git --json=v1 - pkgx git --version - pkgx --silent +git - pkgx --quiet +git - pkgx +git -- git --version # lib/utils.rs:find_program - pkgx --shellcode || true - pkgx -qq git --version - pkgx -s git --version - pkgx -j +git - pkgx /usr/bin/awk --version + - run: pkgx --help + - run: pkgx --version + - run: pkgx +git + - run: pkgx +git --json + - run: pkgx +git --json=v1 + - run: pkgx git --version + - run: pkgx --silent +git + - run: pkgx --quiet +git + - run: pkgx +git -- git --version # lib/utils.rs:find_program + - run: pkgx --shellcode || true + - run: pkgx -qq git --version + - run: pkgx -s git --version + - run: pkgx -j +git + - run: pkgx /usr/bin/awk --version + - run: pkgx +yarnpkg.com yarn --version + - run: pkgx +yarnpkg.com -- yarn --version + - run: '! pkgx yarn --version' - name: generate coverage run: | diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 836fa09f..2b4f2b2a 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -67,6 +67,30 @@ async fn main() -> Result<(), Box> { let mut pkgs = vec![]; + for pkgspec in plus { + let PackageReq { + project: project_or_cmd, + constraint, + } = PackageReq::parse(&pkgspec)?; + if config + .pantry_dir + .join("projects") + .join(project_or_cmd.clone()) + .is_dir() + { + pkgs.push(PackageReq { + project: project_or_cmd, + constraint, + }); + } else { + let project = which(&project_or_cmd, &conn, &pkgs).await?; + pkgs.push(PackageReq { + project, + constraint, + }); + } + } + if find_program { let PackageReq { constraint, @@ -75,7 +99,7 @@ async fn main() -> Result<(), Box> { args[0] = cmd.clone(); // invoke eg. `node` rather than eg. `node@20` - let project = match which(&cmd, &conn).await { + let project = match which(&cmd, &conn, &pkgs).await { Err(WhichError::CmdNotFound(cmd)) => { if !did_sync { if let Some(spinner) = &spinner { @@ -87,7 +111,7 @@ async fn main() -> Result<(), Box> { if let Some(spinner) = &spinner { spinner.set_message("resolving pkg graph…"); } - which(&cmd, &conn).await + which(&cmd, &conn, &pkgs).await } else { Err(WhichError::CmdNotFound(cmd)) } @@ -102,30 +126,6 @@ async fn main() -> Result<(), Box> { }); } - for pkgspec in plus { - let PackageReq { - project: project_or_cmd, - constraint, - } = PackageReq::parse(&pkgspec)?; - if config - .pantry_dir - .join("projects") - .join(project_or_cmd.clone()) - .is_dir() - { - pkgs.push(PackageReq { - project: project_or_cmd, - constraint, - }); - } else { - let project = which(&project_or_cmd, &conn).await?; - pkgs.push(PackageReq { - project, - constraint, - }); - } - } - let companions = pantry_db::companions_for_projects( &pkgs .iter() @@ -262,14 +262,28 @@ impl std::fmt::Display for WhichError { impl std::error::Error for WhichError {} -async fn which(cmd: &String, conn: &Connection) -> Result { +async fn which(cmd: &String, conn: &Connection, pkgs: &[PackageReq]) -> Result { let candidates = pantry_db::which(cmd, conn).map_err(WhichError::DbError)?; if candidates.len() == 1 { Ok(candidates[0].clone()) } else if candidates.is_empty() { - return Err(WhichError::CmdNotFound(cmd.clone())); + Err(WhichError::CmdNotFound(cmd.clone())) } else { - return Err(WhichError::MultipleProjects(cmd.clone(), candidates)); + let selected_pkgs = candidates + .clone() + .into_iter() + .filter(|candidate| { + pkgs.iter().any(|pkg| { + let PackageReq { project, .. } = pkg; + project == candidate + }) + }) + .collect::>(); + if selected_pkgs.len() == 1 { + Ok(selected_pkgs[0].clone()) + } else { + Err(WhichError::MultipleProjects(cmd.clone(), candidates)) + } } }