diff --git a/Cargo.lock b/Cargo.lock index 7292a2f..a3d5a05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +dependencies = [ + "gimli", +] + [[package]] name = "adler" version = "1.0.2" @@ -119,6 +128,21 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" +dependencies = [ + "addr2line", + "cc", + "cfg-if 1.0.0", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base64" version = "0.13.1" @@ -392,6 +416,44 @@ dependencies = [ "serde_yaml", ] +[[package]] +name = "clap" +version = "4.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d7ae14b20b94cb02149ed21a86c423859cbe18dc7ed69845cace50e52b40a5" +dependencies = [ + "backtrace", + "bitflags", + "clap_derive", + "clap_lex", + "is-terminal", + "once_cell", + "strsim", + "termcolor", +] + +[[package]] +name = "clap_derive" +version = "4.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44bec8e5c9d09e439c4335b1af0abaab56dcf3b94999a936e1bb47b9134288f0" +dependencies = [ + "heck 0.4.1", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "350b9cf31731f9957399229e9b2adc51eeabdfbe9d71d9a0552275fd12710d09" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "cocoa" version = "0.24.1" @@ -1037,6 +1099,12 @@ dependencies = [ "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "gimli" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" + [[package]] name = "gio" version = "0.15.12" @@ -1284,6 +1352,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "html5ever" version = "0.25.2" @@ -1538,6 +1612,18 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" +[[package]] +name = "is-terminal" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys 0.45.0", +] + [[package]] name = "itoa" version = "0.4.8" @@ -2050,7 +2136,7 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ - "hermit-abi", + "hermit-abi 0.2.6", "libc", ] @@ -2114,6 +2200,15 @@ dependencies = [ "objc", ] +[[package]] +name = "object" +version = "0.30.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.17.1" @@ -2204,6 +2299,12 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "os_str_bytes" +version = "6.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" + [[package]] name = "overload" version = "0.1.1" @@ -2820,6 +2921,12 @@ dependencies = [ "windows 0.37.0", ] +[[package]] +name = "rustc-demangle" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" + [[package]] name = "rustc_version" version = "0.4.0" @@ -3594,6 +3701,15 @@ dependencies = [ "utf-8", ] +[[package]] +name = "termcolor" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +dependencies = [ + "winapi-util", +] + [[package]] name = "thin-slice" version = "0.1.1" @@ -4545,6 +4661,11 @@ dependencies = [ [[package]] name = "wormhole-cli" version = "0.1.0" +dependencies = [ + "clap", + "tokio 1.26.0", + "wormhole-common", +] [[package]] name = "wormhole-common" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 7f739a6..f8273f1 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -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" } diff --git a/cli/src/cli.rs b/cli/src/cli.rs new file mode 100644 index 0000000..88cc287 --- /dev/null +++ b/cli/src/cli.rs @@ -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, +} + +#[derive(Subcommand, Debug, Clone, Copy)] +pub enum Commands { + Mod { + #[command(subcommand)] + command: Option, + }, + + Instance { + #[command(subcommand)] + command: Option, + }, +} + +#[derive(Subcommand, Debug, Clone, Copy)] +pub enum ModCommands { + Install { + id: i32, + instance_id: Option, + }, + + Info { + id: i32, + instance_id: Option, + }, + + Remove { + id: i32, + instance_id: Option, + }, +} + +#[derive(Subcommand, Debug, Clone, Copy)] +pub enum InstanceCommands { + List {}, + Create {}, + Delete {}, + Info {}, +} diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs new file mode 100644 index 0000000..d4d53da --- /dev/null +++ b/cli/src/commands/mod.rs @@ -0,0 +1 @@ +pub mod mods; diff --git a/cli/src/commands/mods/install.rs b/cli/src/commands/mods/install.rs new file mode 100644 index 0000000..bf0c313 --- /dev/null +++ b/cli/src/commands/mods/install.rs @@ -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!"); + } +} diff --git a/cli/src/commands/mods/mod.rs b/cli/src/commands/mods/mod.rs new file mode 100644 index 0000000..e5b1d65 --- /dev/null +++ b/cli/src/commands/mods/mod.rs @@ -0,0 +1 @@ +pub mod install; diff --git a/cli/src/main.rs b/cli/src/main.rs index e7a11a9..06a96d7 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -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; + }, + + _ => (), + }; + } + }, + + _ => (), + }; + } } diff --git a/common/src/mods/spacedock/mod.rs b/common/src/mods/spacedock/mod.rs index 5548555..fa9df0b 100644 --- a/common/src/mods/spacedock/mod.rs +++ b/common/src/mods/spacedock/mod.rs @@ -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::(&text).unwrap();