Skip to content

Commit

Permalink
take Criterion as self
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19 committed Jan 30, 2023
1 parent b4af699 commit 386ee88
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ pub struct Args {
}

impl Args {
pub fn criterion(&self) -> Criterion {
match &self {
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.clone()),
_ 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"),
}
}
Expand Down
24 changes: 16 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod fingerprint;
mod stamp;
mod util;

use self::cli::Criterion;
use self::cli::{Args, Criterion};
use self::fingerprint::{remove_not_built_with, remove_older_than, remove_older_until_fits};
use self::stamp::Timestamp;
use self::util::format_bytes;
Expand Down Expand Up @@ -132,24 +132,32 @@ fn metadata(path: &Path) -> Result<Metadata, Error> {
fn main() -> anyhow::Result<()> {
let args = cli::parse();

let criterion = args.criterion();
let dry_run = args.dry_run;
setup_logging(args.verbose);
let Args {
ref path,
dry_run,
hidden,
recursive,
verbose,
..
} = args;

// Default to current invocation path.
let path = args
.path
let path = path
.clone()
.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()
.store(path.as_path())
.context("Failed to write timestamp file");
}

let paths = if args.recursive {
find_cargo_projects(&path, args.hidden)
let paths = if recursive {
find_cargo_projects(&path, hidden)
} else {
let metadata = metadata(&path).context(format!(
"Failed to gather metadata for {:?}",
Expand Down

0 comments on commit 386ee88

Please sign in to comment.