summaryrefslogtreecommitdiffstats
path: root/ozone-cli/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ozone-cli/src/main.rs')
-rw-r--r--ozone-cli/src/main.rs63
1 files changed, 47 insertions, 16 deletions
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(&gt)),
+ _ => 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)