Skip to content

Commit

Permalink
Let find_installed_package report any non globally installed package
Browse files Browse the repository at this point in the history
  • Loading branch information
olivier-lacroix committed May 5, 2024
1 parent 17b5407 commit 3f08109
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/cli/global/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub fn bin_env_dir() -> Option<PathBuf> {
/// # Returns
///
/// The package name from the given MatchSpec
pub(super) fn package_name(package_matchspec: &MatchSpec) -> miette::Result<PackageName> {
fn package_name(package_matchspec: &MatchSpec) -> miette::Result<PackageName> {
package_matchspec.name.clone().ok_or_else(|| {
miette::miette!(
"could not find package name in MatchSpec {}",
Expand Down
25 changes: 1 addition & 24 deletions src/cli/global/upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;
use std::time::Duration;

use clap::Parser;
Expand All @@ -16,7 +16,6 @@ use super::common::{
find_installed_package, get_client_and_sparse_repodata, load_package_records, HasSpecs,
};
use super::install::globally_install_package;
use super::list::list_global_packages;

/// Upgrade specific package which is installed globally.
#[derive(Parser, Debug)]
Expand Down Expand Up @@ -47,29 +46,7 @@ impl HasSpecs for Args {

pub async fn execute(args: Args) -> miette::Result<()> {
let config = Config::load_global();

// Get the MatchSpec(s) we need to upgrade
let specs = args.specs()?;

// Return with error if any package is not globally installed.
let global_packages = list_global_packages()
.await?
.into_iter()
.collect::<HashSet<_>>();
let requested = specs.keys().cloned().collect::<HashSet<_>>();
let not_installed = requested.difference(&global_packages).collect_vec();
match not_installed.len() {
0 => {} // Do nothing when all packages are globally installed
1 => miette::bail!(
"Package {} is not globally installed",
not_installed[0].as_normalized(),
),
_ => miette::bail!(
"Packages {} are not globally installed",
not_installed.iter().map(|p| p.as_normalized()).join(", "),
),
};

upgrade_packages(specs, config, &args.channel).await
}

Expand Down

0 comments on commit 3f08109

Please sign in to comment.