From c1a7e38117308a867dbc91a63bbb58c09cc51434 Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Thu, 13 Feb 2025 15:25:04 -0600 Subject: wip: account management cli --- ozone-cli/src/cli.rs | 18 ++++++++++++++- ozone-cli/src/main.rs | 63 ++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 64 insertions(+), 17 deletions(-) (limited to 'ozone-cli/src') diff --git a/ozone-cli/src/cli.rs b/ozone-cli/src/cli.rs index 15a00da..6ba23d3 100644 --- a/ozone-cli/src/cli.rs +++ b/ozone-cli/src/cli.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; use clap::{Args, Parser, Subcommand}; use clap::error::ErrorKind; +use uuid::Uuid; use ozone::launcher::{Instance, InstanceVersion, JavaRuntimeSetting, Resolution}; #[derive(Args, Debug)] @@ -160,9 +161,24 @@ impl InstanceArgs { } } +#[derive(Args, Debug)] +pub struct ProfileSelectArgs { + #[arg(index = 1, conflicts_with_all = ["uuid", "xuid", "gamertag"])] + pub name: Option, + + #[arg(long, conflicts_with_all = ["name", "xuid", "gamertag"])] + pub uuid: Option, + + #[arg(long, conflicts_with_all = ["name", "uuid", "gamertag"])] + pub xuid: Option, + + #[arg(long, short = 'g', alias = "gt", conflicts_with_all = ["name", "uuid", "xuid"])] + pub gamertag: Option +} + #[derive(Subcommand, Debug)] pub enum AccountCommand { - Select, + Select(ProfileSelectArgs), Forget, SignIn } diff --git a/ozone-cli/src/main.rs b/ozone-cli/src/main.rs index 4a8f368..62f7155 100644 --- a/ozone-cli/src/main.rs +++ b/ozone-cli/src/main.rs @@ -9,21 +9,38 @@ use ozone::launcher::{Instance, JavaRuntimeSetting, Launcher, Settings}; use ozone::launcher::version::{VersionList, VersionResult}; use uuid::Uuid; use ozone::auth::{Account, AuthenticationDatabase}; -use crate::cli::{Cli, InstanceCommand, RootCommand}; - -fn find_account<'a>(auth: &'a AuthenticationDatabase, input: &str) -> Vec<&'a Account> { - if let Ok(uuid) = input.parse::() { - todo!() +use crate::cli::{AccountCommand, Cli, InstanceCommand, ProfileSelectArgs, RootCommand}; + +fn find_account<'a>(auth: &'a AuthenticationDatabase, input: &ProfileSelectArgs) -> Result, ()> { + if let Some(uuid) = input.uuid { + Ok(auth.users.iter().filter(|a| match *a { + Account::Dummy(p) => p.id == uuid, + Account::MSA(account) => account.player_profile.as_ref().is_some_and(|p| p.id == uuid) + }).collect()) + } else if let Some(ref name) = input.name { + let name = name.to_ascii_lowercase(); + + Ok(auth.users.iter().filter(|a| match *a { + Account::Dummy(profile) => profile.name.to_ascii_lowercase().starts_with(&name), + Account::MSA(account) => + account.player_profile.as_ref().is_some_and(|p| p.name.to_ascii_lowercase().starts_with(&name)) + }).collect()) + } else if let Some(ref gt) = input.gamertag { + let gt = gt.to_ascii_lowercase(); + + Ok(auth.users.iter().filter(|a| match *a { + Account::MSA(account) => account.gamertag.as_ref().is_some_and(|g| g.to_ascii_lowercase().starts_with(>)), + _ => false + }).collect()) + } else if let Some(ref xuid) = input.xuid { + Ok(auth.users.iter().filter(|a| match *a { + Account::MSA(account) => account.xuid.as_ref().is_some_and(|x| x == xuid), + _ => false + }).collect()) + } else { + eprintln!("No account specified."); + Err(()) } - - 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) { @@ -59,7 +76,7 @@ async fn main_inner(cli: Cli) -> Result> { let mut settings = Settings::load(home.join("ozone.json")).await?; match &cli.subcmd { - RootCommand::Instance(p) => match p.command() { + RootCommand::Instance(inst_args) => match inst_args.command() { InstanceCommand::List => { let mut first = true; @@ -202,6 +219,21 @@ async fn main_inner(cli: Cli) -> Result> { settings.save().await?; } }, + RootCommand::Account(account_args) => { + // TODO: load auth db and do stuff with it + + match &account_args.command { + AccountCommand::Select(args) => { + + }, + AccountCommand::Forget => { + + }, + AccountCommand::SignIn => { + + } + } + } RootCommand::Launch => { let Some(selection) = settings.selected_instance else { eprintln!("No instance selected."); @@ -224,7 +256,6 @@ async fn main_inner(cli: Cli) -> Result> { ozone::launcher::run_the_game(&launch)?; } - _ => todo!() } Ok(ExitCode::SUCCESS) -- cgit v1.2.3-70-g09d2