pub mod cli;
#[macro_use]
mod migrations;
mod matching;
mod modifying;
use std::fmt::Display;
use std::io::{self, Write};
fn instructive_error<E: Display, I: Display>(error: E, instructions: &[I]) -> String {
let mut error_message = vec![format!("{error}")];
instructions
.iter()
.map(|inst| format!(" {inst}"))
.for_each(|inst| error_message.push(inst));
error_message.join("\n")
}
fn internal_error<E: Display>(error: E) -> String {
instructive_error(error, &[
"This is an internal error and signifies a bug in the `forc migrate` tool.",
"Please report this error by filing an issue at https://github.com/FuelLabs/sway/issues/new?template=bug_report.yml.",
])
}
fn print_single_choice_menu<S: AsRef<str> + Display>(options: &[S]) -> usize {
assert!(
options.len() > 1,
"There must be at least two options to choose from."
);
for (i, option) in options.iter().enumerate() {
println!("{}. {option}", i + 1);
}
let mut choice = usize::MAX;
while choice == 0 || choice > options.len() {
print!("Enter your choice [1..{}]: ", options.len());
io::stdout().flush().unwrap();
let mut input = String::new();
choice = match std::io::stdin().read_line(&mut input) {
Ok(_) => match input.trim().parse() {
Ok(choice) => choice,
Err(_) => continue,
},
Err(_) => continue,
}
}
choice - 1
}