diff --git a/src/lib.rs b/src/lib.rs index 47477c4..9802394 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,7 +50,10 @@ pub use error::{Error, Result}; /// /// This implments the `verifyConditions` step for `sementic-release` for a /// Cargo-based rust workspace. -pub fn verify_conditions(mut output: impl Write, manifest_path: Option<&PathBuf>) -> Result<()> { +pub fn verify_conditions( + mut output: impl Write, + manifest_path: Option>, +) -> Result<()> { info!("Checking CARGO_REGISTRY_TOKEN"); env::var_os("CARGO_REGISTRY_TOKEN") .and_then(|val| if val.is_empty() { None } else { Some(()) }) @@ -123,7 +126,11 @@ pub fn verify_conditions(mut output: impl Write, manifest_path: Option<&PathBuf> // TODO: remove when not needed #[allow(missing_docs)] -pub fn prepare(_output: impl Write, _manifest_path: Option<&PathBuf>, _version: &str) -> Result<()> { +pub fn prepare( + _output: impl Write, + _manifest_path: Option>, + _version: &str, +) -> Result<()> { todo!() } @@ -136,7 +143,10 @@ pub fn prepare(_output: impl Write, _manifest_path: Option<&PathBuf>, _version: /// /// This is a debuging aid and does not directly correspond to a sementic release /// step. -pub fn list_packages(mut output: impl Write, manifest_path: Option<&PathBuf>) -> Result<()> { +pub fn list_packages( + mut output: impl Write, + manifest_path: Option>, +) -> Result<()> { info!("Building package graph"); let graph = get_package_graph(manifest_path)?; @@ -155,7 +165,9 @@ pub fn list_packages(mut output: impl Write, manifest_path: Option<&PathBuf>) -> Ok(()) } -fn get_package_graph(manifest_path: Option<&PathBuf>) -> Result { +fn get_package_graph(manifest_path: Option>) -> Result { + let manifest_path = manifest_path.as_ref().map(|path| path.as_ref()); + let mut command = MetadataCommand::new(); if let Some(path) = manifest_path { command.manifest_path(path); @@ -165,7 +177,7 @@ fn get_package_graph(manifest_path: Option<&PathBuf>) -> Result { command.build_graph().map_err(|err| { let path = match manifest_path { - Some(path) => path.clone(), + Some(path) => path.to_path_buf(), None => env::current_dir() .map(|path| path.join("Cargo.toml")) .unwrap_or_else(|e| { diff --git a/src/main.rs b/src/main.rs index 0446d8a..cb3a797 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use std::fs::File; use std::io::{prelude::*, stdout, BufWriter}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use anyhow::{Context, Error}; use human_panic::setup_panic; @@ -95,9 +95,9 @@ impl Subcommand { use Subcommand::*; match self { - ListPackages(opt) => Ok(list_packages(w, (&opt.manifest_path).into())?), - VerifyConditions(opt) => Ok(verify_conditions(w, (&opt.manifest_path).into())?), - Prepare(opt) => Ok(prepare(w, (&opt.common.manifest_path).into(), &opt.next_version)?), + ListPackages(opt) => Ok(list_packages(w, opt.manifest_path())?), + VerifyConditions(opt) => Ok(verify_conditions(w, opt.manifest_path())?), + Prepare(opt) => Ok(prepare(w, opt.common.manifest_path(), &opt.next_version)?), } } } @@ -124,3 +124,9 @@ fn main() -> Result<(), Error> { None => opt.subcommand.run(BufWriter::new(stdout())), } } + +impl CommonOpt { + fn manifest_path(&self) -> Option<&Path> { + self.manifest_path.as_ref().map(|path| path.as_path()) + } +}