diff --git a/src/cli.rs b/src/cli.rs index 736792f..17dc8ee 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -88,30 +88,30 @@ pub struct Args { } impl Args { - pub fn criterion(self) -> Criterion { + pub fn criterion(&self) -> Criterion { match self { _ if self.stamp => Criterion::Stamp, _ if self.file => Criterion::File, _ if self.installed => Criterion::Installed, - _ if !self.toolchains.is_empty() => Criterion::Toolchains(self.toolchains), + _ if !self.toolchains.is_empty() => Criterion::Toolchains(&self.toolchains), Self { time: Some(time), .. - } => Criterion::Time(time), + } => Criterion::Time(*time), Self { maxsize: Some(size), .. - } => Criterion::MaxSize(size), + } => Criterion::MaxSize(*size), _ => unreachable!("guaranteed by clap ArgGroup"), } } } -pub enum Criterion { +pub enum Criterion<'a> { Stamp, File, Time(u64), Installed, - Toolchains(Vec), + Toolchains(&'a [String]), MaxSize(u64), } diff --git a/src/main.rs b/src/main.rs index 2dcf7a6..434aa64 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ mod fingerprint; mod stamp; mod util; -use self::cli::{Args, Criterion}; +use self::cli::Criterion; use self::fingerprint::{remove_not_built_with, remove_older_than, remove_older_until_fits}; use self::stamp::Timestamp; use self::util::format_bytes; @@ -132,23 +132,17 @@ fn metadata(path: &Path) -> Result { fn main() -> anyhow::Result<()> { let args = cli::parse(); - let Args { - ref path, - dry_run, - hidden, - recursive, - verbose, - .. - } = args; + let dry_run = args.dry_run; + let criterion = args.criterion(); + setup_logging(args.verbose); // Default to current invocation path. - let path = path - .clone() + let path = args + .path + .as_ref() + .cloned() .unwrap_or_else(|| env::current_dir().expect("Failed to get current directory")); - let criterion = args.criterion(); - setup_logging(verbose); - if let Criterion::Stamp = criterion { debug!("Writing timestamp file in: {:?}", path); return Timestamp::new() @@ -156,8 +150,8 @@ fn main() -> anyhow::Result<()> { .context("Failed to write timestamp file"); } - let paths = if recursive { - find_cargo_projects(&path, hidden) + let paths = if args.recursive { + find_cargo_projects(&path, args.hidden) } else { let metadata = metadata(&path).context(format!( "Failed to gather metadata for {:?}", @@ -173,7 +167,7 @@ fn main() -> anyhow::Result<()> { let toolchains = match &criterion { Criterion::Installed => Some(vec![]), - Criterion::Toolchains(vec) => Some(vec).cloned(), + Criterion::Toolchains(vec) => Some(vec.to_vec()), _ => None, }; if let Some(toolchains) = toolchains {