From 5893ec213fc0027e1221df7a5b8066deef0e723b Mon Sep 17 00:00:00 2001 From: David Gilligan-Cook Date: Wed, 11 Sep 2024 10:52:31 -0700 Subject: [PATCH] Adds --allow-already-editable flag to spfs edit commands This flag stops spfs edit from exiting with an error when the runtime environment is already editable. Signed-off-by: David Gilligan-Cook --- crates/spfs-cli/main/src/cmd_edit.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/crates/spfs-cli/main/src/cmd_edit.rs b/crates/spfs-cli/main/src/cmd_edit.rs index 6e237b917d..e2698d5488 100644 --- a/crates/spfs-cli/main/src/cmd_edit.rs +++ b/crates/spfs-cli/main/src/cmd_edit.rs @@ -4,6 +4,7 @@ use clap::Args; use miette::Result; +use spfs::Error; /// Make the current runtime editable #[derive(Debug, Args)] @@ -15,6 +16,10 @@ pub struct CmdEdit { /// Change a runtime into a durable runtime, will also make the runtime editable #[clap(long)] keep_runtime: bool, + + /// Do not exit with an error when the runtime environment is already editable + #[clap(long)] + allow_already_editable: bool, } impl CmdEdit { @@ -37,16 +42,19 @@ impl CmdEdit { if !self.off { match spfs::make_active_runtime_editable().await { Ok(_) => tracing::info!("edit mode enabled"), - Err(err) => { - if self.keep_runtime { - // When --keep-runtime was also given, being - // already editable isn't an error, but still - // want to tell the user about it - tracing::info!("{err}") + Err(Error::RuntimeAlreadyEditable) => { + if self.keep_runtime || self.allow_already_editable { + // When these options are given, being already + // editable isn't an error, but still want to + // tell the user about it + tracing::info!("{}", Error::RuntimeAlreadyEditable) } else { - return Err(err.into()); + return Err(Error::RuntimeAlreadyEditable.into()); } } + Err(err) => { + return Err(err.into()); + } }; } else { let mut rt = spfs::active_runtime().await?;