Skip to content

Commit 64d2212

Browse files
committed
feat(oplog): add --force flag to skip restore confirmation and
1 parent 62f98d6 commit 64d2212

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

crates/but/src/args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ For examples see `but rub --help`."
110110
Restore {
111111
/// Oplog SHA to restore to
112112
oplog_sha: String,
113+
/// Skip confirmation prompt
114+
#[clap(short = 'f', long = "force")]
115+
force: bool,
113116
},
114117
/// Undo the last operation by reverting to the previous snapshot.
115118
Undo,

crates/but/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ async fn main() -> Result<()> {
220220
metrics_if_configured(app_settings, CommandName::Oplog, props(start, &result)).ok();
221221
result
222222
}
223-
Subcommands::Restore { oplog_sha } => {
223+
Subcommands::Restore { oplog_sha, force } => {
224224
let project = get_or_init_project(&args.current_dir)?;
225-
let result = oplog::restore_to_oplog(&project, args.json, oplog_sha);
225+
let result = oplog::restore_to_oplog(&project, args.json, oplog_sha, *force);
226226
metrics_if_configured(app_settings, CommandName::Restore, props(start, &result)).ok();
227227
result
228228
}

crates/but/src/oplog/mod.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub(crate) fn restore_to_oplog(
117117
project: &Project,
118118
_json: bool,
119119
oplog_sha: &str,
120+
force: bool,
120121
) -> anyhow::Result<()> {
121122
let snapshots = but_api::undo::list_snapshots(project.id, 1000, None, None)?;
122123

@@ -160,23 +161,25 @@ pub(crate) fn restore_to_oplog(
160161
println!(" Snapshot: {}", commit_sha_string[..7].cyan().underline());
161162

162163
// Confirm the restoration (safety check)
163-
println!(
164-
"\n{}",
165-
"⚠️ This will overwrite your current workspace state."
166-
.yellow()
167-
.bold()
168-
);
169-
print!("Continue with restore? [y/N]: ");
170-
use std::io::{self, Write};
171-
io::stdout().flush()?;
172-
173-
let mut input = String::new();
174-
io::stdin().read_line(&mut input)?;
175-
176-
let input = input.trim().to_lowercase();
177-
if input != "y" && input != "yes" {
178-
println!("{}", "Restore cancelled.".yellow());
179-
return Ok(());
164+
if !force {
165+
println!(
166+
"\n{}",
167+
"⚠️ This will overwrite your current workspace state."
168+
.yellow()
169+
.bold()
170+
);
171+
print!("Continue with restore? [y/N]: ");
172+
use std::io::{self, Write};
173+
io::stdout().flush()?;
174+
175+
let mut input = String::new();
176+
io::stdin().read_line(&mut input)?;
177+
178+
let input = input.trim().to_lowercase();
179+
if input != "y" && input != "yes" {
180+
println!("{}", "Restore cancelled.".yellow());
181+
return Ok(());
182+
}
180183
}
181184

182185
// Restore to the target snapshot using the but-api crate

0 commit comments

Comments
 (0)