From 3f6ae858bcaa82c3fcf04e4e84856decdff3b431 Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Wed, 26 Jun 2024 21:53:30 -0300 Subject: [PATCH] add download_link option to update and create, and token arg to login --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/index.rs | 39 ++++++++++++++++++++++++++++----------- src/index_admin.rs | 2 +- src/index_auth.rs | 11 +++++++++-- src/util/mod_file.rs | 2 +- 6 files changed, 41 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index de8737b..f35fc10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -982,7 +982,7 @@ dependencies = [ [[package]] name = "geode" -version = "3.0.4" +version = "3.0.5" dependencies = [ "ansi_term", "cfg-if 1.0.0", diff --git a/Cargo.toml b/Cargo.toml index bd52455..8bab19e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "geode" -version = "3.0.4" +version = "3.0.5" authors = [ "HJfod ", "Camila314 ", diff --git a/src/index.rs b/src/index.rs index 5fb8952..c26303f 100644 --- a/src/index.rs +++ b/src/index.rs @@ -32,7 +32,11 @@ pub enum Index { }, /// Login with your GitHub account - Login, + Login { + /// Existing access token to use + #[clap(long)] + token: Option, + }, /// Invalidate all existing access tokens (logout) Invalidate, @@ -72,9 +76,15 @@ pub enum Index { #[derive(Deserialize, Debug, Clone, Subcommand, PartialEq)] pub enum MyModAction { /// Create a new mod - Create, + Create { + /// Direct download link to the .geode file + download_link: Option, + }, /// Update an existing mod - Update, + Update { + /// Direct download link to the .geode file + download_link: Option, + }, /// List your published mods Published, /// List your pending mods @@ -247,22 +257,29 @@ fn create_entry(out_path: &Path) { } fn submit(action: MyModAction, config: &mut Config) { - if action != MyModAction::Create && action != MyModAction::Update { - fatal!("Invalid action"); - } + let mut is_update = false; + let download_link = match action { + MyModAction::Create { download_link } => download_link, + MyModAction::Update { download_link } => { + is_update = true; + download_link + } + _ => fatal!("Invalid action"), + }; if config.index_token.is_none() { fatal!("You are not logged in"); } - let download_link = ask_value("Download URL for the .geode file", None, true); + let download_link = + download_link.unwrap_or_else(|| ask_value("Download URL for the .geode file", None, true)); let mut id: Option = None; #[derive(Deserialize)] struct SimpleModJson { id: String, } - if action == MyModAction::Update { + if is_update { info!("Fetching mod id from .geode file"); let mut zip_data: Cursor> = Cursor::new(vec![]); @@ -453,7 +470,7 @@ pub fn subcommand(config: &mut Config, cmd: Index) { install_mod(config, &id, &version.unwrap_or(VersionReq::STAR), false); done!("Mod installed"); } - Index::Login => index_auth::login(config), + Index::Login { token } => index_auth::login(config, token), Index::Invalidate => index_auth::invalidate(config), Index::Url { url } => { if let Some(u) = url { @@ -463,8 +480,8 @@ pub fn subcommand(config: &mut Config, cmd: Index) { } } Index::Mods { action } => match action { - MyModAction::Create => submit(action, config), - MyModAction::Update => submit(action, config), + MyModAction::Create { .. } => submit(action, config), + MyModAction::Update { .. } => submit(action, config), MyModAction::Published => index_dev::print_own_mods(true, config), MyModAction::Pending => index_dev::print_own_mods(false, config), MyModAction::Edit => index_dev::edit_own_mods(config), diff --git a/src/index_admin.rs b/src/index_admin.rs index 7036c88..e42dabf 100644 --- a/src/index_admin.rs +++ b/src/index_admin.rs @@ -2,7 +2,7 @@ use std::fmt::Display; use crate::{ config::Config, - fail, fatal, + fatal, index::{self, AdminAction}, index_dev::{self, DeveloperProfile}, info, diff --git a/src/index_auth.rs b/src/index_auth.rs index 672a937..c4b6439 100644 --- a/src/index_auth.rs +++ b/src/index_auth.rs @@ -20,11 +20,18 @@ struct LoginPoll { uuid: String, } -pub fn login(config: &mut Config) { +pub fn login(config: &mut Config, token: Option) { + if let Some(token) = token { + config.index_token = Some(token); + config.save(); + done!("Successfully logged in with the provided token"); + return; + } + if config.index_token.is_some() { warn!("You are already logged in"); let token = config.index_token.clone().unwrap(); - info!("{}", token); + info!("Your token is: {}", token); return; } diff --git a/src/util/mod_file.rs b/src/util/mod_file.rs index 6b6f909..3714492 100644 --- a/src/util/mod_file.rs +++ b/src/util/mod_file.rs @@ -97,7 +97,7 @@ pub trait ToGeodeString { impl ToGeodeString for VersionReq { fn to_geode_string(&self) -> String { // geode uses = instead of ^ for exact version - self.to_string().replace("^", "=") + self.to_string().replace('^', "=") } }