From 0295809436d8e178a7d0528b47b9d4313b292eef Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 18 Jan 2021 14:48:59 +0100 Subject: Run `cargo fmt` Signed-off-by: Matthias Beyer --- src/main.rs | 78 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 30 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index d553d9f..d3e9304 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,17 +34,17 @@ // unused_qualifications, while_true, )] - #![allow(macro_use_extern_crate)] extern crate log as logcrate; -#[macro_use] extern crate diesel; +#[macro_use] +extern crate diesel; use std::path::Path; use std::path::PathBuf; -use anyhow::Result; use anyhow::anyhow; +use anyhow::Result; use clap::ArgMatches; use logcrate::debug; use walkdir::WalkDir; @@ -78,7 +78,8 @@ async fn main() -> Result<()> { let cli = app.get_matches(); let repo = git2::Repository::discover(PathBuf::from("."))?; - let repo_path = repo.workdir() + let repo_path = repo + .workdir() .ok_or_else(|| anyhow!("Not a repository with working directory. Cannot do my job!"))?; let mut config = ::config::Config::default(); @@ -87,14 +88,16 @@ async fn main() -> Result<()> { .merge(::config::File::from(repo_path.join("config.toml")))? .merge(::config::Environment::with_prefix("BUTIDO"))?; - let config = config - .try_into::()? - .validate()?; + let config = config.try_into::()?.validate()?; - let _ = crate::ui::package_repo_cleanness_check(&repo_path)?; - let max_packages = count_pkg_files(&repo_path); - let hide_bars = cli.is_present("hide_bars") || crate::util::stdout_is_pipe(); - let progressbars = ProgressBars::setup(config.progress_format().clone(), config.spinner_format().clone(), hide_bars); + let _ = crate::ui::package_repo_cleanness_check(&repo_path)?; + let max_packages = count_pkg_files(&repo_path); + let hide_bars = cli.is_present("hide_bars") || crate::util::stdout_is_pipe(); + let progressbars = ProgressBars::setup( + config.progress_format().clone(), + config.spinner_format().clone(), + hide_bars, + ); let load_repo = || -> Result { let bar = progressbars.bar(); @@ -106,48 +109,58 @@ async fn main() -> Result<()> { let db_connection_config = crate::db::parse_db_connection_config(&config, &cli); match cli.subcommand() { - Some(("generate-completions", matches)) => generate_completions(matches)?, - Some(("db", matches)) => crate::commands::db(db_connection_config, &config, matches)?, - Some(("build", matches)) => { + Some(("generate-completions", matches)) => generate_completions(matches)?, + Some(("db", matches)) => crate::commands::db(db_connection_config, &config, matches)?, + Some(("build", matches)) => { let conn = crate::db::establish_connection(db_connection_config)?; let repo = load_repo()?; - crate::commands::build(&repo_path, matches, progressbars, conn, &config, repo, &repo_path, max_packages).await? - }, + crate::commands::build( + &repo_path, + matches, + progressbars, + conn, + &config, + repo, + &repo_path, + max_packages, + ) + .await? + } Some(("what-depends", matches)) => { let repo = load_repo()?; let bar = progressbars.bar(); bar.set_length(max_packages); crate::commands::what_depends(matches, &config, repo).await? - }, + } Some(("dependencies-of", matches)) => { let repo = load_repo()?; let bar = progressbars.bar(); bar.set_length(max_packages); crate::commands::dependencies_of(matches, &config, repo).await? - }, + } Some(("versions-of", matches)) => { let repo = load_repo()?; crate::commands::versions_of(matches, repo).await? - }, + } Some(("env-of", matches)) => { let repo = load_repo()?; crate::commands::env_of(matches, repo).await? - }, + } Some(("find-pkg", matches)) => { let repo = load_repo()?; crate::commands::find_pkg(matches, &config, repo).await? - }, + } Some(("source", matches)) => { let repo = load_repo()?; crate::commands::source(matches, &config, repo, progressbars).await? - }, + } Some(("release", matches)) => { crate::commands::release(db_connection_config, &config, matches).await? @@ -164,7 +177,7 @@ async fn main() -> Result<()> { } Some((other, _)) => return Err(anyhow!("Unknown subcommand: {}", other)), - None => return Err(anyhow!("No subcommand")), + None => return Err(anyhow!("No subcommand")), } Ok(()) @@ -176,7 +189,12 @@ fn count_pkg_files(p: &Path) -> u64 { .into_iter() .filter_map(Result::ok) .filter(|d| d.file_type().is_file()) - .filter(|f| f.path().file_name().map(|name| name == "pkg.toml").unwrap_or(false)) + .filter(|f| { + f.path() + .file_name() + .map(|name| name == "pkg.toml") + .unwrap_or(false) + }) .count() as u64 } @@ -185,22 +203,22 @@ fn generate_completions(matches: &ArgMatches) -> Result<()> { use clap_generate::generators::{Bash, Elvish, Fish, Zsh}; let appname = "butido"; - match matches.value_of("shell").unwrap() { // unwrap safe by clap + match matches.value_of("shell").unwrap() { + // unwrap safe by clap "bash" => { generate::(&mut cli::cli(), appname, &mut std::io::stdout()); - }, + } "elvish" => { generate::(&mut cli::cli(), appname, &mut std::io::stdout()); - }, + } "fish" => { generate::(&mut cli::cli(), appname, &mut std::io::stdout()); - }, + } "zsh" => { generate::(&mut cli::cli(), appname, &mut std::io::stdout()); - }, + } _ => unreachable!(), } Ok(()) } - -- cgit v1.2.3