diff options
| -rw-r--r-- | ozone-cli/src/cli.rs | 18 | ||||
| -rw-r--r-- | ozone-cli/src/main.rs | 63 |
2 files changed, 64 insertions, 17 deletions
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<String>,
+
+ #[arg(long, conflicts_with_all = ["name", "xuid", "gamertag"])]
+ pub uuid: Option<Uuid>,
+
+ #[arg(long, conflicts_with_all = ["name", "uuid", "gamertag"])]
+ pub xuid: Option<String>,
+
+ #[arg(long, short = 'g', alias = "gt", conflicts_with_all = ["name", "uuid", "xuid"])]
+ pub gamertag: Option<String>
+}
+
#[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::<Uuid>() { - todo!() +use crate::cli::{AccountCommand, Cli, InstanceCommand, ProfileSelectArgs, RootCommand}; + +fn find_account<'a>(auth: &'a AuthenticationDatabase, input: &ProfileSelectArgs) -> Result<Vec<&'a Account>, ()> { + 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<Path>, selected: bool, verbose: bool) { @@ -59,7 +76,7 @@ async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> { 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<ExitCode, Box<dyn Error>> { 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<ExitCode, Box<dyn Error>> { ozone::launcher::run_the_game(&launch)?; } - _ => todo!() } Ok(ExitCode::SUCCESS) |
