Skip to content

Commit

Permalink
add download_link option to update and create, and token arg to login
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Jun 27, 2024
1 parent 4cd20de commit 3f6ae85
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "geode"
version = "3.0.4"
version = "3.0.5"
authors = [
"HJfod <dreadrollmusic@gmail.com>",
"Camila314 <ilaca314@gmail.com>",
Expand Down
39 changes: 28 additions & 11 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ pub enum Index {
},

/// Login with your GitHub account
Login,
Login {
/// Existing access token to use
#[clap(long)]
token: Option<String>,
},

/// Invalidate all existing access tokens (logout)
Invalidate,
Expand Down Expand Up @@ -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<String>,
},
/// Update an existing mod
Update,
Update {
/// Direct download link to the .geode file
download_link: Option<String>,
},
/// List your published mods
Published,
/// List your pending mods
Expand Down Expand Up @@ -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<String> = 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<Vec<u8>> = Cursor::new(vec![]);

Expand Down Expand Up @@ -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 {
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/index_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Display;

use crate::{
config::Config,
fail, fatal,
fatal,
index::{self, AdminAction},
index_dev::{self, DeveloperProfile},
info,
Expand Down
11 changes: 9 additions & 2 deletions src/index_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ struct LoginPoll {
uuid: String,
}

pub fn login(config: &mut Config) {
pub fn login(config: &mut Config, token: Option<String>) {
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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/mod_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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('^', "=")
}
}

Expand Down

0 comments on commit 3f6ae85

Please sign in to comment.