...
 
Commits (2)
[package]
name = "cargo-upgrades"
version = "1.0.0"
version = "1.1.0"
authors = ["Kornel <[email protected]>"]
categories = ["development-tools::cargo-plugins"]
repository = "https://gitlab.com/kornelski/cargo-upgrades"
......@@ -13,8 +13,7 @@ readme = "README.md"
[dependencies]
cargo_metadata = "0.8.1"
cargo_toml = "0.7.0"
clap = "2.33.0"
quick-error = "1.2.2"
semver = "0.9.0"
crates-index = "0.13.2"
getopts = "0.2.19"
use cargo_metadata::CargoOpt;
use cargo_metadata::Dependency;
use crates_index::Crate;
use cargo_metadata::PackageId;
use cargo_metadata::MetadataCommand;
use cargo_metadata::Package;
use std::collections::HashMap;
use semver::Version;
use cargo_metadata::PackageId;
use crates_index::Crate;
use quick_error::quick_error;
pub use crates_index::Error as IndexError;
use semver::Version;
use std::collections::HashMap;
pub use cargo_metadata::Error as MetadataError;
pub use crates_index::Error as IndexError;
quick_error! {
#[derive(Debug)]
......@@ -62,17 +64,25 @@ pub struct Match<'a> {
impl Workspace {
pub fn new(manifest_path: Option<&str>) -> Result<Self, MetadataError> {
let mut cmd = cargo_metadata::MetadataCommand::new();
if let Some(path) = manifest_path {
cmd.manifest_path(path);
}
let metadata = cmd.exec()?;
let mut cmd = Self::new_metadata(manifest_path, CargoOpt::AllFeatures);
let metadata = cmd.exec().or_else(|_| {
Self::new_metadata(manifest_path, CargoOpt::NoDefaultFeatures)
}.exec())?;
Ok(Self {
packages: metadata.packages.into_iter().map(|p| (p.id.clone(), p)).collect(),
members: metadata.workspace_members,
})
}
fn new_metadata(manifest_path: Option<&str>, features: CargoOpt) -> MetadataCommand {
let mut cmd = MetadataCommand::new();
if let Some(path) = manifest_path {
cmd.manifest_path(path);
}
cmd.features(features);
cmd
}
pub fn check_package(&self, id: &PackageId, index: &HashMap<Box<str>, Crate>) -> Option<(&Package, Vec<Match>)> {
let package = self.packages.get(id)?;
let deps = package.dependencies.iter().filter_map(|dep| {
......
use cargo_upgrades::*;
use clap::*;
fn main() {
// When run via Cargo, the command name is present
let args = std::env::args().enumerate().filter(|&(i,ref a)| {
i != 1 || a != "upgrades"
}).map(|(_,a)| a);
let args: Vec<_> = std::env::args().collect();
let matches = App::new(crate_name!())
.version(crate_version!())
.about(crate_description!())
.arg(
Arg::with_name("manifest-path")
.long("manifest-path")
.value_name("Cargo.toml")
.takes_value(true),
)
.get_matches_from(args);
let mut opts = getopts::Options::new();
opts.optopt("", "manifest-path", "Alternative location", "Cargo.toml");
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(e) => {
eprintln!("cargo-upgrades v{}\n{}\nUsage: {} --manifest-path=Cargo.toml", env!("CARGO_PKG_VERSION"), e, args[0]);
std::process::exit(1);
}
};
let manifest_path = matches.value_of("manifest-path");
let u = match UpgradesChecker::new(manifest_path) {
let manifest_path = matches.opt_str("manifest-path");
let u = match UpgradesChecker::new(manifest_path.as_ref().map(|s| s.as_str())) {
Ok(u) => u,
Err(e) => {
eprintln!("error: {}", e);
......