Skip to content

Commit

Permalink
Adds --allow-already-editable flag to spfs edit commands
Browse files Browse the repository at this point in the history
This flag stops spfs edit from exiting with an error when the runtime
environment is already editable.

Signed-off-by: David Gilligan-Cook <dcook@imageworks.com>
  • Loading branch information
dcookspi committed Sep 11, 2024
1 parent 19ff372 commit 5893ec2
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions crates/spfs-cli/main/src/cmd_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use clap::Args;
use miette::Result;
use spfs::Error;

/// Make the current runtime editable
#[derive(Debug, Args)]
Expand All @@ -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 {
Expand All @@ -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?;
Expand Down

0 comments on commit 5893ec2

Please sign in to comment.