diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-08-13 15:39:54 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-08-13 15:39:57 +0200 |
commit | f84a396fb60394a0f1d22e0eb9e8a30602d75a7a (patch) | |
tree | 54daa552bb8d7760bcc2e86796043ef4545872bd | |
parent | 2d4945938be440411e43c3440a368df0f70e5810 (diff) |
Make Repository::load() interface async
Not the enterior of the function, yet.
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r-- | src/main.rs | 33 | ||||
-rw-r--r-- | src/repository/repository.rs | 2 |
2 files changed, 18 insertions, 17 deletions
diff --git a/src/main.rs b/src/main.rs index 18dee07..0384beb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -141,12 +141,13 @@ async fn main() -> Result<()> { hide_bars, ); - let load_repo = || -> Result<Repository> { - let bar = progressbars.bar(); - let repo = Repository::load(repo_path, &bar) + let repo_loading_bar = progressbars.bar(); + let load_repo = async move { + let repo = Repository::load(repo_path, &repo_loading_bar) + .await .context("Loading the repository")?; - bar.finish_with_message("Repository loading finished"); - Ok(repo) + repo_loading_bar.finish_with_message("Repository loading finished"); + Ok(repo) as Result<_> }; let db_connection_config = crate::db::DbConnectionConfig::parse(&config, &cli)?; @@ -156,7 +157,7 @@ async fn main() -> Result<()> { Some(("build", matches)) => { let conn = db_connection_config.establish_connection(&progressbars)?; - let repo = load_repo()?; + let repo = load_repo.await?; crate::commands::build( repo_path, @@ -171,35 +172,35 @@ async fn main() -> Result<()> { .context("build command failed")? } Some(("what-depends", matches)) => { - let repo = load_repo()?; + let repo = load_repo.await?; crate::commands::what_depends(matches, &config, repo) .await .context("what-depends command failed")? } Some(("dependencies-of", matches)) => { - let repo = load_repo()?; + let repo = load_repo.await?; crate::commands::dependencies_of(matches, &config, repo) .await .context("dependencies-of command failed")? } Some(("versions-of", matches)) => { - let repo = load_repo()?; + let repo = load_repo.await?; crate::commands::versions_of(matches, repo) .await .context("versions-of command failed")? } Some(("env-of", matches)) => { - let repo = load_repo()?; + let repo = load_repo.await?; crate::commands::env_of(matches, repo) .await .context("env-of command failed")? } Some(("find-artifact", matches)) => { - let repo = load_repo()?; + let repo = load_repo.await?; let conn = db_connection_config.establish_connection(&progressbars)?; crate::commands::find_artifact(matches, &config, progressbars, repo, conn) .await @@ -207,14 +208,14 @@ async fn main() -> Result<()> { } Some(("find-pkg", matches)) => { - let repo = load_repo()?; + let repo = load_repo.await?; crate::commands::find_pkg(matches, &config, repo) .await .context("find-pkg command failed")? } Some(("source", matches)) => { - let repo = load_repo()?; + let repo = load_repo.await?; crate::commands::source(matches, &config, repo, progressbars) .await .context("source command failed")? @@ -227,21 +228,21 @@ async fn main() -> Result<()> { } Some(("lint", matches)) => { - let repo = load_repo()?; + let repo = load_repo.await?; crate::commands::lint(repo_path, matches, progressbars, &config, repo) .await .context("lint command failed")? } Some(("tree-of", matches)) => { - let repo = load_repo()?; + let repo = load_repo.await?; crate::commands::tree_of(matches, repo) .await .context("tree-of command failed")? } Some(("metrics", _)) => { - let repo = load_repo()?; + let repo = load_repo.await?; let conn = db_connection_config.establish_connection(&progressbars)?; crate::commands::metrics(repo_path, &config, repo, conn) .await diff --git a/src/repository/repository.rs b/src/repository/repository.rs index 170c2b0..7a3b4eb 100644 --- a/src/repository/repository.rs +++ b/src/repository/repository.rs @@ -39,7 +39,7 @@ impl From<BTreeMap<(PackageName, PackageVersion), Package>> for Repository { } impl Repository { - pub fn load(path: &Path, progress: &indicatif::ProgressBar) -> Result<Self> { + pub async fn load(path: &Path, progress: &indicatif::ProgressBar) -> Result<Self> { fn all_subdirs(p: &Path) -> Result<Vec<PathBuf>> { let mut v = Vec::new(); for de in p.read_dir()? { |