Skip to content

Commit

Permalink
Sad bugs fixed and work on cli
Browse files Browse the repository at this point in the history
  • Loading branch information
RedstoneWizard08 committed Mar 10, 2023
1 parent cb8463b commit 3837704
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 4 deletions.
123 changes: 122 additions & 1 deletion Cargo.lock

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

3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4.1.8", features = ["derive", "env", "string", "debug"] }
tokio = { version = "1.26.0", features = ["full"] }
wormhole-common = { path = "../common" }
50 changes: 50 additions & 0 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use clap::{Parser, Subcommand};

#[derive(Parser, Debug, Clone, Copy)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
#[arg(short, long)]
pub verbose: bool,

#[command(subcommand)]
pub command: Option<Commands>,
}

#[derive(Subcommand, Debug, Clone, Copy)]
pub enum Commands {
Mod {
#[command(subcommand)]
command: Option<ModCommands>,
},

Instance {
#[command(subcommand)]
command: Option<InstanceCommands>,
},
}

#[derive(Subcommand, Debug, Clone, Copy)]
pub enum ModCommands {
Install {
id: i32,
instance_id: Option<i32>,
},

Info {
id: i32,
instance_id: Option<i32>,
},

Remove {
id: i32,
instance_id: Option<i32>,
},
}

#[derive(Subcommand, Debug, Clone, Copy)]
pub enum InstanceCommands {
List {},
Create {},
Delete {},
Info {},
}
1 change: 1 addition & 0 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod mods;
19 changes: 19 additions & 0 deletions cli/src/commands/mods/install.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use wormhole_common::{installer::mods::ModInstaller, finder::find_install_dir};

pub async fn install_mod(id: i32, verbose: bool) {
if verbose {
println!("Creating mod installer...");
}

let installer = ModInstaller::new(find_install_dir());

if verbose {
println!("Installing mod...");
}

installer.install_from_spacedock(id).await;

if verbose {
println!("Mod installed!");
}
}
1 change: 1 addition & 0 deletions cli/src/commands/mods/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod install;
36 changes: 34 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
fn main() {
println!("Hello, world!");
pub mod cli;
pub mod commands;

use clap::Parser;
use cli::{Cli, Commands, ModCommands};
use commands::mods::install::install_mod;
use tokio::main;

#[main]
pub async fn main() {
let cli = Cli::parse();
let verbose = cli.verbose;

if verbose {
println!("Command: {:?}", cli.command);
}

if let Some(scmd) = cli.command {
match scmd {
Commands::Mod { command } => {
if let Some(scmd) = command {
match scmd {
ModCommands::Install { id, instance_id } => {
install_mod(id, verbose).await;
},

_ => (),
};
}
},

_ => (),
};
}
}
2 changes: 1 addition & 1 deletion common/src/mods/spacedock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl SpaceDockAPI {
}

pub async fn get_mod_download(&self, id: i32) -> String {
let uri = format!("{}/mod/${}/latest", self.base.clone(), id);
let uri = format!("{}/mod/{}/latest", self.base.clone(), id);
let resp = reqwest::get(uri).await.unwrap();
let text = resp.text().await.unwrap();
let data = serde_json::from_str::<LatestSchema>(&text).unwrap();
Expand Down

0 comments on commit 3837704

Please sign in to comment.