From ae9727f42c7059dd1ae751411dded1819c6c0a11 Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Thu, 13 Feb 2025 14:54:31 -0600 Subject: overhaul auth errors --- ozone-cli/src/main.rs | 64 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 24 deletions(-) (limited to 'ozone-cli/src/main.rs') diff --git a/ozone-cli/src/main.rs b/ozone-cli/src/main.rs index c53eade..4a8f368 100644 --- a/ozone-cli/src/main.rs +++ b/ozone-cli/src/main.rs @@ -1,6 +1,7 @@ mod cli; use std::error::Error; +use std::path::Path; use std::process::ExitCode; use log::{error, info, trace, LevelFilter}; use clap::Parser; @@ -10,12 +11,42 @@ use uuid::Uuid; use ozone::auth::{Account, AuthenticationDatabase}; use crate::cli::{Cli, InstanceCommand, RootCommand}; -fn find_account(auth: &AuthenticationDatabase, input: &str) -> Option { - for user in auth.users.iter() { - +fn find_account<'a>(auth: &'a AuthenticationDatabase, input: &str) -> Vec<&'a Account> { + if let Ok(uuid) = input.parse::() { + todo!() + } + + let input = input.to_ascii_lowercase(); + + auth.users.iter().filter(|a| match *a { + Account::Dummy(profile) => profile.name.to_ascii_lowercase().starts_with(&input), + Account::MSA(account) => + account.player_profile.as_ref().is_some_and(|p| p.name.to_ascii_lowercase().starts_with(&input)) || + account.gamertag.as_ref().is_some_and(|p| p.to_ascii_lowercase().starts_with(&input)) + }).collect() +} + +fn display_instance(instance: &Instance, id: Uuid, home: impl AsRef, selected: bool, verbose: bool) { + println!("Instance `{}':{}", instance.name, if selected { " (selected)" } else { "" }); + println!(" UUID: {}", id); + println!(" Version: {}", instance.game_version); + println!(" Location: {}", home.as_ref().join(Settings::get_instance_path(id)).display()); + + if !verbose { return; } + + if let Some(ref args) = instance.jvm_arguments { + println!(" JVM arguments: <{} argument{}>", args.len(), if args.len() == 1 { "" } else { "s" }) + } + + if let Some(res) = instance.resolution { + println!(" Resolution: {}x{}", res.width, res.height); + } + + match &instance.java_runtime { + Some(JavaRuntimeSetting::Component(c)) => println!(" Java runtime component: {c}"), + Some(JavaRuntimeSetting::Path(p)) => println!(" Java runtime path: {}", p.display()), + _ => () } - - todo!() } async fn main_inner(cli: Cli) -> Result> { @@ -45,12 +76,8 @@ async fn main_inner(cli: Cli) -> Result> { first = false; let cur_id = *cur_id; - let sel = if settings.selected_instance.is_some_and(|id| id == cur_id) { " (selected)" } else { "" }; - - println!("Instance `{}'{sel}:", instance.name); - println!(" UUID: {}", cur_id); - println!(" Version: {}", instance.game_version); - println!(" Location: {}", home.join(Settings::get_instance_path(cur_id)).display()); + let sel = settings.selected_instance.is_some_and(|id| id == cur_id); + display_instance(instance, cur_id, &home, sel, false); } }, InstanceCommand::Create(args) => { @@ -158,18 +185,7 @@ async fn main_inner(cli: Cli) -> Result> { return Ok(ExitCode::FAILURE); }; - println!("Information for selected profile `{}' ({}):", inst.name, settings.selected_instance.unwrap()); - println!(" Version: {}", inst.game_version); - - match &inst.java_runtime { - Some(JavaRuntimeSetting::Component(c)) => println!(" Java runtime component: {c}"), - Some(JavaRuntimeSetting::Path(p)) => println!(" Java runtime path: {}", p.display()), - _ => () - } - - if let Some(res) = inst.resolution { - println!(" Game resolution: {}x{}", res.width, res.height); - } + display_instance(inst, settings.selected_instance.unwrap(), &home, false, true); }, InstanceCommand::Rename { name } => { if name.is_empty() { @@ -182,7 +198,7 @@ async fn main_inner(cli: Cli) -> Result> { return Ok(ExitCode::FAILURE); }; - inst.name.replace_range(.., &name); + inst.name.replace_range(.., name); settings.save().await?; } }, -- cgit v1.2.3-70-g09d2