From 912916abebd1f921261244ee8a4a7dfa40c11a9c Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Mon, 10 Feb 2025 02:35:07 -0600 Subject: last commit before rewriting settings system?? --- ozone-cli/src/main.rs | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'ozone-cli/src/main.rs') diff --git a/ozone-cli/src/main.rs b/ozone-cli/src/main.rs index adfeb71..e0cbada 100644 --- a/ozone-cli/src/main.rs +++ b/ozone-cli/src/main.rs @@ -2,10 +2,10 @@ mod cli; use std::error::Error; use std::process::ExitCode; -use log::{error, info, trace}; +use log::{error, info, trace, LevelFilter}; use clap::Parser; -use ozone::launcher::{Launcher, Settings}; -use ozone::launcher::version::VersionList; +use ozone::launcher::{Instance, Launcher, Profile, Settings}; +use ozone::launcher::version::{VersionList, VersionResult}; use crate::cli::{Cli, ProfileCommand, RootCommand}; async fn main_inner(cli: Cli) -> Result> { @@ -38,7 +38,7 @@ async fn main_inner(cli: Cli) -> Result> { let exists = if settings.get_instances().contains_key(profile.get_instance_name()) { "" } else { " (missing!)" }; println!("Profile {name}:{sel}"); - println!(" Version: {}", profile.get_version()); + println!(" Version: {}", profile.game_version); println!(" Instance: {}{}", profile.get_instance_name(), exists); } }, @@ -48,23 +48,46 @@ async fn main_inner(cli: Cli) -> Result> { return Ok(ExitCode::FAILURE); } - if let Some(ref src) = args.clone { + if let Err(e) = Profile::check_name(&args.name) { + eprintln!("The profile name is invalid: {e}"); + return Ok(ExitCode::FAILURE); + } + + let mut profile = if let Some(ref src) = args.clone { if let Some(profile) = settings.get_profiles().get(src) { - let profile = profile.clone(); - settings.profiles.insert(args.name.clone(), profile); + profile.clone() } else { eprintln!("Unknown profile `{src}'."); return Ok(ExitCode::FAILURE); } + } else { + let inst_name = args.instance.as_ref().unwrap_or(&args.name); + if let Err(e) = Instance::check_name(inst_name) { + eprintln!("The profile name is invalid for an instance: {e}"); + eprintln!("Please specify an instance name manually with --instance."); + return Ok(ExitCode::FAILURE); + } - return Ok(ExitCode::SUCCESS); - } + Profile::new(inst_name) + }; // creating a new profile from scratch todo!() }, ProfileCommand::Select(args) => { - + let ver = VersionList::new(home.join("versions"), !cli.offline).await?; + + match ver.get_version_lazy(&args.profile) { + VersionResult::None => { + println!("Unknown version"); + }, + VersionResult::Remote(v) => { + println!("Remote version: {v:?}"); + }, + VersionResult::Complete(v) => { + println!("Complete version: {v:?}"); + } + } } _ => todo!() }, @@ -92,7 +115,8 @@ async fn main_inner(cli: Cli) -> Result> { #[tokio::main] async fn main() -> ExitCode { - simple_logger::SimpleLogger::new().env().init().unwrap(); + // use Warn as the default level to minimize noise on the command line + simple_logger::SimpleLogger::new().with_level(LevelFilter::Warn).env().init().unwrap(); let arg = Cli::parse(); -- cgit v1.2.3-70-g09d2