Skip to content

Commit

Permalink
feat: vrc-get outdated
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Jan 30, 2023
1 parent fd1cf49 commit 17f900c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ For more details, please see --help

- [x] `vrc-get install [pkg] [version]` (with alias `vrc-get i [pkg] [version]`)
- [x] `vrc-get remove [pkg]` (with alias `vrc-get rm [pkg]`)
- [x] `vrc-get outdated`
- [x] `vrc-get repo list`
- [x] `vrc-get repo add <url> [NAME]`
- [x] `vrc-get repo remove <name or url>`
Expand Down
59 changes: 58 additions & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::vpm::{download_remote_repository, VersionSelector};
use clap::{Parser, Subcommand};
use reqwest::Url;
use serde_json::{from_value, Map, Value};
use std::collections::HashMap;
use std::ffi::{OsStr, OsString};
use std::path::{Path, PathBuf};
use std::process::exit;
Expand All @@ -29,11 +30,12 @@ pub enum Command {
Install(Install),
#[command(alias = "rm")]
Remove(Remove),
Outdated(Outdated),
#[command(subcommand)]
Repo(Repo),
}

multi_command!(Command is Install, Remove, Repo);
multi_command!(Command is Install, Remove, Outdated, Repo);

/// Adds package to unity project
#[derive(Parser)]
Expand Down Expand Up @@ -115,6 +117,61 @@ impl Remove {
}
}

/// Show list of outdated packages
#[derive(Parser)]
#[command(author, version)]
pub struct Outdated {
/// Path to project dir. by default CWD or parents of CWD will be used
#[arg(short = 'p', long = "project")]
project: Option<PathBuf>,
}

impl Outdated {
pub async fn run(self) {
let client = crate::create_client();
let env = crate::vpm::Environment::load_default(client)
.await
.expect("loading global config");
let unity = crate::vpm::UnityProject::find_unity_project(self.project)
.await
.expect("unity project not found");

let mut outdated_packages = HashMap::new();

for (name, dep) in unity.locked_packages() {
match env
.find_package_by_name(name, VersionSelector::Latest)
.await
{
Err(e) => log::error!("error loading package {}: {}", name, e),
Ok(None) => log::error!("package {} not found.", name),
// if found version is newer: add to outdated
Ok(Some(pkg)) if dep.version < pkg.version => {
outdated_packages.insert(pkg.name.clone(), (pkg, &dep.version));
}
Ok(Some(_)) => (),
}
}

for dep in unity.locked_packages().values() {
for (name, range) in &dep.dependencies {
if let Some((outdated, _)) = outdated_packages.get(name) {
if !range.matches(&outdated.version) {
outdated_packages.remove(name);
}
}
}
}

for (name, (found, installed)) in &outdated_packages {
println!(
"{}: installed: {}, found: {}",
name, installed, &found.version
);
}
}
}

/// Commands around repositories
#[derive(Subcommand)]
#[command(author, version)]
Expand Down
4 changes: 4 additions & 0 deletions src/vpm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,10 @@ impl UnityProject {
.await?;
Ok(())
}

pub(crate) fn locked_packages(&self) -> &IndexMap<String, VpmLockedDependency> {
return self.manifest.locked();
}
}

pub enum VersionSelector<'a> {
Expand Down

0 comments on commit 17f900c

Please sign in to comment.