Skip to content

Commit

Permalink
xtask: Improve publish failure UX
Browse files Browse the repository at this point in the history
by offering the user more actions to choose from when an error occured.
  • Loading branch information
har7an committed Aug 20, 2023
1 parent 4860b90 commit 66aeace
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions xtask/src/pipelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ pub fn dist(sh: &Shell, _flags: flags::Dist) -> anyhow::Result<()> {
.with_context(err_context)
}

/// Actions for the user to choose from to resolve publishing errors/conflicts.
enum UserAction {
Retry,
Abort,
Ignore,
}

/// Make a zellij release and publish all crates.
pub fn publish(sh: &Shell, flags: flags::Publish) -> anyhow::Result<()> {
let err_context = "failed to publish zellij";
Expand Down Expand Up @@ -333,37 +340,42 @@ pub fn publish(sh: &Shell, flags: flags::Publish) -> anyhow::Result<()> {
println!("Publishing crate '{crate_name}' failed with error:");
println!("{:?}", err);
println!();
println!("Retry? [y/n]");
println!("Please choose what to do: [r]etry/[a]bort/[i]gnore");

let stdin = std::io::stdin();
let mut buffer = String::new();
let retry: bool;
let action;

loop {
let mut buffer = String::new();
stdin.read_line(&mut buffer).context(err_context)?;

match buffer.trim_end() {
"y" | "Y" => {
retry = true;
"r" | "R" => {
action = UserAction::Retry;
break;
},
"a" | "A" => {
action = UserAction::Abort;
break;
},
"n" | "N" => {
retry = false;
"i" | "I" => {
action = UserAction::Ignore;
break;
},
_ => {
println!(" --> Unknown input '{buffer}', ignoring...");
println!();
println!("Retry? [y/n]");
println!("Please choose what to do: [r]etry/[a]bort/[i]gnore");
},
}
}

if retry {
continue;
} else {
println!("Aborting publish for crate '{crate_name}'");
return Err::<(), _>(err);
match action {
UserAction::Retry => continue,
UserAction::Ignore => break,
UserAction::Abort => {
eprintln!("Aborting publish for crate '{crate_name}'");
return Err::<(), _>(err);
},
}
} else {
// publish successful, continue to next crate
Expand Down

0 comments on commit 66aeace

Please sign in to comment.