From a9d5d24a358e4f82cdb38d7a30ad659870791f85 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:24:41 +0000 Subject: [PATCH] Clean up OPAM if requested (#12) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OPAM has a built-in `clean` command that automatically removes download caches, logs, and cleans the current OPAM switch. We should call `opam clean` when the cleanup flag is set. Authored-by: Victor Song Approved-by: Thomas Schönauer --- src/main.rs | 2 +- src/steps/generic.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index ea591742..5d8ac775 100644 --- a/src/main.rs +++ b/src/main.rs @@ -318,7 +318,7 @@ fn run() -> Result<()> { runner.execute(Step::Flutter, "Flutter", || generic::run_flutter_upgrade(run_type))?; runner.execute(Step::Go, "Go", || generic::run_go(run_type))?; runner.execute(Step::Emacs, "Emacs", || emacs.upgrade(&ctx))?; - runner.execute(Step::Opam, "opam", || generic::run_opam_update(run_type))?; + runner.execute(Step::Opam, "opam", || generic::run_opam_update(&ctx))?; runner.execute(Step::Vcpkg, "vcpkg", || generic::run_vcpkg_update(run_type))?; runner.execute(Step::Pipx, "pipx", || generic::run_pipx_update(run_type))?; runner.execute(Step::Conda, "conda", || generic::run_conda_update(&ctx))?; diff --git a/src/steps/generic.rs b/src/steps/generic.rs index 485bd7d5..9f7dae43 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -220,13 +220,19 @@ pub fn run_rtcl(ctx: &ExecutionContext) -> Result<()> { ctx.run_type().execute(&rupdate).check_run() } -pub fn run_opam_update(run_type: RunType) -> Result<()> { +pub fn run_opam_update(ctx: &ExecutionContext) -> Result<()> { let opam = utils::require("opam")?; print_separator("OCaml Package Manager"); - run_type.execute(&opam).arg("update").check_run()?; - run_type.execute(&opam).arg("upgrade").check_run() + ctx.run_type().execute(&opam).arg("update").check_run()?; + ctx.run_type().execute(&opam).arg("upgrade").check_run()?; + + if ctx.config().cleanup() { + ctx.run_type().execute(&opam).arg("clean").check_run()?; + } + + Ok(()) } pub fn run_vcpkg_update(run_type: RunType) -> Result<()> {