treewide: remove dead code

Also deletes some dead_code annotations from functions that are
*actually used*.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ic815cacc93c464078ead1674e7523d8b6a6a6964
This commit is contained in:
raf 2026-02-28 23:08:26 +03:00
commit 0a15e0b1f3
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
3 changed files with 30 additions and 112 deletions

View file

@ -2,7 +2,7 @@
use std::io;
use dialoguer::{Confirm, Input, MultiSelect, Select, theme::ColorfulTheme};
use dialoguer::{Confirm, Input, Select, theme::ColorfulTheme};
/// Creates a terminal hyperlink using OSC 8 escape sequence
/// Format: \x1b]8;;<URL>\x1b\\<TEXT>\x1b]8;;\x1b\\
@ -12,7 +12,16 @@ pub fn hyperlink(url: &str, text: &str) -> String {
/// Prompts user with a yes/no question
/// Returns true for yes, false for no
pub fn prompt_yes_no(question: &str, default: bool) -> io::Result<bool> {
/// If `skip_prompts` is true, returns the default value without prompting
pub fn prompt_yes_no(
question: &str,
default: bool,
skip_prompts: bool,
) -> io::Result<bool> {
if skip_prompts {
return Ok(default);
}
Confirm::with_theme(&ColorfulTheme::default())
.with_prompt(question)
.default(default)
@ -22,7 +31,6 @@ pub fn prompt_yes_no(question: &str, default: bool) -> io::Result<bool> {
/// Prompts user to select from a list of options
/// Returns the index of the selected option
#[allow(dead_code)]
pub fn prompt_select(question: &str, options: &[&str]) -> io::Result<usize> {
Select::with_theme(&ColorfulTheme::default())
.with_prompt(question)
@ -32,28 +40,12 @@ pub fn prompt_select(question: &str, options: &[&str]) -> io::Result<usize> {
.map_err(io::Error::other)
}
/// Prompts user to select multiple items from a list
/// Returns the indices of the selected options
#[allow(dead_code)]
pub fn prompt_multi_select(
question: &str,
options: &[&str],
) -> io::Result<Vec<usize>> {
MultiSelect::with_theme(&ColorfulTheme::default())
.with_prompt(question)
.items(options)
.interact()
.map_err(io::Error::other)
}
/// Creates a formatted project URL for Modrinth
#[allow(dead_code)]
pub fn modrinth_project_url(slug: &str) -> String {
format!("https://modrinth.com/mod/{slug}")
}
/// Creates a formatted project URL for `CurseForge`
#[allow(dead_code)]
pub fn curseforge_project_url(project_id: &str) -> String {
format!("https://www.curseforge.com/minecraft/mc-mods/{project_id}")
}
@ -118,16 +110,22 @@ pub fn suggest_similar<'a>(
/// Prompt user if they meant a similar project name.
/// Returns `Some(suggested_name)` if user confirms, None otherwise.
/// If `skip_prompts` is true, automatically accepts the first suggestion.
pub fn prompt_typo_suggestion(
input: &str,
candidates: &[String],
skip_prompts: bool,
) -> io::Result<Option<String>> {
// Use a max distance based on input length for reasonable suggestions
let max_distance = (input.len() / 2).clamp(2, 4);
let suggestions = suggest_similar(input, candidates, max_distance);
if let Some(first_suggestion) = suggestions.first()
&& prompt_yes_no(&format!("Did you mean '{first_suggestion}'?"), true)?
&& prompt_yes_no(
&format!("Did you mean '{first_suggestion}'?"),
true,
skip_prompts,
)?
{
return Ok(Some((*first_suggestion).to_string()));
}
@ -164,7 +162,14 @@ pub fn prompt_input_optional(prompt: &str) -> io::Result<Option<String>> {
/// Prompt for `CurseForge` API key when authentication fails.
/// Returns the API key if provided, None if cancelled.
pub fn prompt_curseforge_api_key() -> io::Result<Option<String>> {
/// If `skip_prompts` is true, returns None immediately.
pub fn prompt_curseforge_api_key(
skip_prompts: bool,
) -> io::Result<Option<String>> {
if skip_prompts {
return Ok(None);
}
use dialoguer::Password;
println!();
@ -172,7 +177,7 @@ pub fn prompt_curseforge_api_key() -> io::Result<Option<String>> {
println!("Get your API key from: https://console.curseforge.com/");
println!();
if !prompt_yes_no("Would you like to enter your API key now?", true)? {
if !prompt_yes_no("Would you like to enter your API key now?", true, false)? {
return Ok(None);
}