utils: reorganize module structure
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I5b51e349ea67e27170e3a3ebe6b1d3fe6a6a6964
This commit is contained in:
parent
f2af2fbbe4
commit
83343bc3dd
3 changed files with 5 additions and 62 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
pub mod hash;
|
pub mod hash;
|
||||||
pub mod id;
|
pub mod id;
|
||||||
pub mod prompt;
|
|
||||||
|
|
||||||
pub use hash::verify_hash;
|
pub use hash::verify_hash;
|
||||||
pub use id::generate_pakku_id;
|
pub use id::generate_pakku_id;
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
use std::io::{self, Write};
|
|
||||||
|
|
||||||
use crate::error::Result;
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn prompt_user(message: &str) -> Result<String> {
|
|
||||||
print!("{message}");
|
|
||||||
io::stdout().flush()?;
|
|
||||||
|
|
||||||
let mut input = String::new();
|
|
||||||
io::stdin().read_line(&mut input)?;
|
|
||||||
|
|
||||||
Ok(input.trim().to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn prompt_select(message: &str, options: &[String]) -> Result<usize> {
|
|
||||||
println!("{message}");
|
|
||||||
for (i, option) in options.iter().enumerate() {
|
|
||||||
println!(" {}. {}", i + 1, option);
|
|
||||||
}
|
|
||||||
|
|
||||||
loop {
|
|
||||||
print!("Select (1-{}): ", options.len());
|
|
||||||
io::stdout().flush()?;
|
|
||||||
|
|
||||||
let mut input = String::new();
|
|
||||||
io::stdin().read_line(&mut input)?;
|
|
||||||
|
|
||||||
if let Ok(choice) = input.trim().parse::<usize>()
|
|
||||||
&& choice > 0
|
|
||||||
&& choice <= options.len()
|
|
||||||
{
|
|
||||||
return Ok(choice - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Invalid selection. Please try again.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn prompt_confirm(message: &str) -> Result<bool> {
|
|
||||||
print!("{message} (y/n): ");
|
|
||||||
io::stdout().flush()?;
|
|
||||||
|
|
||||||
let mut input = String::new();
|
|
||||||
io::stdin().read_line(&mut input)?;
|
|
||||||
|
|
||||||
let answer = input.trim().to_lowercase();
|
|
||||||
Ok(answer == "y" || answer == "yes")
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn confirm(message: &str) -> Result<bool> {
|
|
||||||
prompt_confirm(message)
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue