Skip to content

Commit

Permalink
basic run command
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlan404 committed Jul 26, 2024
1 parent 77ae0b5 commit 3767d8e
Show file tree
Hide file tree
Showing 22 changed files with 281 additions and 94 deletions.
8 changes: 4 additions & 4 deletions src/api/app/actions/build/server_jar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use anyhow::Result;
use crate::api::{app::App, models::Environment};

impl App {
/// Installs the server jar according to [`crate::api::models::server::Server::jar`]
/// Installs the server jar according to [`crate::api::models::server::Server::get_jar`]
pub async fn action_install_jar(&self, base: &Path) -> Result<()> {
if let Some(jar) = self.server.read().await.as_ref().map(|(_, server)| {
server.jar.clone()
}).flatten() {
if let Some((_, server)) = &*self.server.read().await {
println!("Installing server jar");

let jar = server.get_jar(&self).await?;

Check failure on line 13 in src/api/app/actions/build/server_jar.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> src/api/app/actions/build/server_jar.rs:13:38 | 13 | let jar = server.get_jar(&self).await?; | ^^^^^ help: change this to: `self` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D clippy::all` = help: to override `-D clippy::all` add `#[allow(clippy::needless_borrow)]`

let steps = jar.resolve_steps(&self, Environment::Server).await?;

Check failure on line 15 in src/api/app/actions/build/server_jar.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> src/api/app/actions/build/server_jar.rs:15:43 | 15 | let steps = jar.resolve_steps(&self, Environment::Server).await?; | ^^^^^ help: change this to: `self` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

self.execute_steps(base, &steps).await?;
Expand Down
47 changes: 1 addition & 46 deletions src/api/app/actions/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,5 @@ use crate::api::{
};

impl App {
pub async fn action_init_server(&self) -> Result<()> {
cliclack::intro("Creating a new server...")?;

let path = PathBuf::from(".").join(SERVER_TOML);

if let Some((_, server)) = &*self.server.read().await {
let con = cliclack::confirm(format!("Server with name '{}' found! Continue?", server.name))
.initial_value(false)
.interact()?;

if con {
cliclack::note("Warning", "Current server might get overwritten")?;
} else {
cliclack::outro_cancel("Cancelled")?;
return Ok(());
}
}

let name: String = cliclack::input("Name of the server?").interact()?;

let mut server = Server {
name,
..Default::default()
};

{
let mut wg = self.server.write().await;
*wg = Some((path, server));
}

cliclack::outro("Saved!")?;

Ok(())
}

pub async fn action_init_network(&self) -> Result<()> {
cliclack::intro("initializing network")?;

let name: String = cliclack::input("Name of the network?").interact()?;

let mut nw = Network { name, ..Default::default() };

//self.network = Some(Arc::new(RwLock::new(nw)));

Ok(())
}

}
6 changes: 1 addition & 5 deletions src/api/app/actions/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ impl App {

let mut args = vec![];

let java = if let Some(v) = &server.launcher.java_version {
get_java_installation_for(*v).await.map(|j| j.path.to_string_lossy().into_owned()).unwrap_or(String::from("java"))
} else {
String::from("java")
};
let java = server.get_java().await;

args.push(java);
args.extend(server.get_arguments());
Expand Down
3 changes: 3 additions & 0 deletions src/api/app/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ impl App {
let mut sources = vec![];

if let Some((server_path, server)) = &*self.server.read().await {
let server_path = server_path.parent().unwrap().to_path_buf();
if let Some((network_path, network)) = &*self.network.read().await {
let network_path = network_path.parent().unwrap().to_path_buf();

if let Some(group) = network.groups.get("global") {
for source in &group.sources {
sources.push((network_path.clone(), source.clone()));
Expand Down
4 changes: 1 addition & 3 deletions src/api/app/step/execute_java.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ impl App {
.find(|j| j.version >= version.unwrap_or_default())
.ok_or(anyhow!("Java with version {} or higher not found, cannot proceed", version.map(|v| v.to_string()).unwrap_or("any".to_owned())))?;

Check warning on line 21 in src/api/app/step/execute_java.rs

View workflow job for this annotation

GitHub Actions / clippy

called `map(<f>).unwrap_or(<a>)` on an `Option` value

warning: called `map(<f>).unwrap_or(<a>)` on an `Option` value --> src/api/app/step/execute_java.rs:21:88 | 21 | ...or higher not found, cannot proceed", version.map(|v| v.to_string()).unwrap_or("any".to_owned())))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or = note: `-W clippy::map-unwrap-or` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::map_unwrap_or)]` help: use `map_or(<a>, <f>)` instead | 21 - .ok_or(anyhow!("Java with version {} or higher not found, cannot proceed", version.map(|v| v.to_string()).unwrap_or("any".to_owned())))?; 21 + .ok_or(anyhow!("Java with version {} or higher not found, cannot proceed", version.map_or("any".to_owned(), |v| v.to_string())))?; |

let args = args.iter().map(String::as_str).collect::<Vec<_>>();

let mut proc = JavaProcess::new(&dir.canonicalize()?, &java.path, &args)?;
let mut proc = JavaProcess::new(&dir.canonicalize()?, &java.path, args)?;

fn on_line(line: &str) {
println!("| {line}");
Expand Down
1 change: 1 addition & 0 deletions src/api/models/launcher/preset_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl PresetFlags {
Self::None => "",
}
.split(char::is_whitespace)
.filter(|x| !x.is_empty())
.map(ToOwned::to_owned)
.collect()
}
Expand Down
9 changes: 8 additions & 1 deletion src/api/models/mrpack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ pub const MRPACK_INDEX_FILE: &str = "modrinth.index.json";

use crate::api::{app::App, utils::accessor::Accessor};

use super::{Addon, AddonTarget, AddonType, Environment};
use super::{server::ServerJar, Addon, AddonTarget, AddonType};


pub async fn resolve_mrpack_serverjar(app: &App, mut accessor: Accessor) -> Result<ServerJar> {
let index: MRPackIndex = accessor.json(app, MRPACK_INDEX_FILE).await?;

Ok(ServerJar::try_from(index.dependencies.clone())?)

Check failure on line 19 in src/api/models/mrpack/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

question mark operator is useless here

error: question mark operator is useless here --> src/api/models/mrpack/mod.rs:19:5 | 19 | Ok(ServerJar::try_from(index.dependencies.clone())?) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `ServerJar::try_from(index.dependencies.clone())` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark
}

pub async fn resolve_mrpack_addons(app: &App, mut accessor: Accessor) -> Result<Vec<Addon>> {
let mut addons = vec![];
Expand Down
12 changes: 9 additions & 3 deletions src/api/models/packwiz/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
mod packwiz_mod;
mod packwiz_pack;

use std::path::{Path, PathBuf};
use std::path::PathBuf;

use anyhow::{bail, Result};
pub use packwiz_mod::*;
pub use packwiz_pack::*;

use crate::api::{app::App, models::AddonType, step::Step, utils::{accessor::Accessor, url::get_filename_from_url}};
use crate::api::{app::App, models::AddonType, step::Step, utils::accessor::Accessor};

pub static PACK_TOML: &str = "pack.toml";

use super::{Addon, AddonTarget};
use super::{server::ServerJar, Addon, AddonTarget};

pub async fn resolve_packwiz_serverjar(app: &App, mut accessor: Accessor) -> Result<ServerJar> {
let pack: PackwizPack = accessor.toml(app, PACK_TOML).await?;

Ok(ServerJar::try_from(pack.versions.clone())?)

Check failure on line 19 in src/api/models/packwiz/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

question mark operator is useless here

error: question mark operator is useless here --> src/api/models/packwiz/mod.rs:19:5 | 19 | Ok(ServerJar::try_from(pack.versions.clone())?) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try removing question mark and `Ok()`: `ServerJar::try_from(pack.versions.clone())` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark
}

pub async fn resolve_packwiz_addons(app: &App, mut accessor: Accessor) -> Result<Vec<Addon>> {
let mut addons = vec![];
Expand Down
34 changes: 32 additions & 2 deletions src/api/models/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::collections::HashMap;

use anyhow::{anyhow, Result};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use super::{launcher::ServerLauncher, markdown::MarkdownOptions, Source};
use crate::api::{app::App, tools::java::get_java_installation_for};

use super::{launcher::ServerLauncher, markdown::MarkdownOptions, mrpack::resolve_mrpack_serverjar, packwiz::resolve_packwiz_serverjar, ModpackType, Source, SourceType};

mod server_flavor;
mod server_type;
Expand Down Expand Up @@ -55,6 +58,33 @@ impl Default for Server {
}

impl Server {
/// Gets the ServerJar via `jar` OR `Source` where `type=modpack`

Check warning on line 61 in src/api/models/server/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

item in documentation is missing backticks

warning: item in documentation is missing backticks --> src/api/models/server/mod.rs:61:18 | 61 | /// Gets the ServerJar via `jar` OR `Source` where `type=modpack` | ^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown help: try | 61 | /// Gets the `ServerJar` via `jar` OR `Source` where `type=modpack` | ~~~~~~~~~~~
pub async fn get_jar(&self, app: &App) -> Result<ServerJar> {
let relative_to = app.server.read().await.as_ref().map(|(p, _)| p.clone());

if let Some(jar) = &self.jar {
Ok(jar.clone())
} else {
let source = self.sources.iter().find(|s| matches!(s.source_type, SourceType::Modpack { .. }))
.ok_or(anyhow!("Can't find a ServerJar type because no [jar] OR Source with type=modpack defined"))?;

let accessor = source.accessor(&relative_to.ok_or(anyhow!("relative_to error"))?)?;
match source.modpack_type().unwrap() {
ModpackType::MRPack => resolve_mrpack_serverjar(app, accessor).await,
ModpackType::Packwiz => resolve_packwiz_serverjar(app, accessor).await,
ModpackType::Unsup => todo!()
}
}
}

pub async fn get_java(&self) -> String {
if let Some(v) = self.launcher.java_version {
get_java_installation_for(v).await.map(|j| j.path.to_string_lossy().into_owned()).unwrap_or(String::from("java"))

Check warning on line 82 in src/api/models/server/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

called `map(<f>).unwrap_or(<a>)` on an `Option` value

warning: called `map(<f>).unwrap_or(<a>)` on an `Option` value --> src/api/models/server/mod.rs:82:13 | 82 | get_java_installation_for(v).await.map(|j| j.path.to_string_lossy().into_owned()).unwrap_or(String::from("java")) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or help: use `map_or(<a>, <f>)` instead | 82 - get_java_installation_for(v).await.map(|j| j.path.to_string_lossy().into_owned()).unwrap_or(String::from("java")) 82 + get_java_installation_for(v).await.map_or(String::from("java"), |j| j.path.to_string_lossy().into_owned()) |
} else {
String::from("java")
}
}

pub fn get_execution_arguments(&self) -> Vec<String> {
self.jar.as_ref().map(|s| s.get_execution_arguments()).unwrap_or_default()

Check warning on line 89 in src/api/models/server/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant closure

warning: redundant closure --> src/api/models/server/mod.rs:89:31 | 89 | self.jar.as_ref().map(|s| s.get_execution_arguments()).unwrap_or_default() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `server_type::ServerJar::get_execution_arguments` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls = note: `-W clippy::redundant-closure-for-method-calls` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::redundant_closure_for_method_calls)]`
}
Expand Down Expand Up @@ -86,6 +116,6 @@ impl Server {

args.extend(self.launcher.game_args.split_whitespace().map(ToOwned::to_owned));

args
args.into_iter().filter(|x| !x.is_empty()).collect()
}
}
41 changes: 40 additions & 1 deletion src/api/models/server/server_type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::collections::HashMap;

use crate::api::{
app::App, models::{Addon, AddonTarget, AddonType, Environment}, sources::buildtools, step::Step, utils::serde::*

Check warning on line 4 in src/api/models/server/server_type.rs

View workflow job for this annotation

GitHub Actions / clippy

usage of wildcard import

warning: usage of wildcard import --> src/api/models/server/server_type.rs:4:102 | 4 | app::App, models::{Addon, AddonTarget, AddonType, Environment}, sources::buildtools, step::Step, utils::serde::* | ^^^^^^^^^^^^^^^ help: try: `utils::serde::str_latest` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports = note: `-W clippy::wildcard-imports` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::wildcard_imports)]`
};
use anyhow::Result;
use anyhow::{anyhow, Result};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -36,6 +38,43 @@ pub struct ServerJar {
pub server_type: ServerType,
}

impl TryFrom<HashMap<String, String>> for ServerJar {
type Error = anyhow::Error;

fn try_from(value: HashMap<String, String>) -> std::result::Result<Self, Self::Error> {
let mut server_type = None;

if let Some(v) = value.get("fabric").cloned() {
server_type = Some(ServerType::Fabric { loader: v, installer: String::from("latest") })

Check warning on line 48 in src/api/models/server/server_type.rs

View workflow job for this annotation

GitHub Actions / clippy

consider adding a `;` to the last statement for consistent formatting

warning: consider adding a `;` to the last statement for consistent formatting --> src/api/models/server/server_type.rs:48:13 | 48 | server_type = Some(ServerType::Fabric { loader: v, installer: String::from("latest") }) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `server_type = Some(ServerType::Fabric { loader: v, installer: String::from("latest") });` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned = note: `-W clippy::semicolon-if-nothing-returned` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::semicolon_if_nothing_returned)]`
}

if let Some(v) = value.get("fabric-loader").cloned() {
server_type = Some(ServerType::Fabric { loader: v, installer: String::from("latest") })

Check warning on line 52 in src/api/models/server/server_type.rs

View workflow job for this annotation

GitHub Actions / clippy

consider adding a `;` to the last statement for consistent formatting

warning: consider adding a `;` to the last statement for consistent formatting --> src/api/models/server/server_type.rs:52:13 | 52 | server_type = Some(ServerType::Fabric { loader: v, installer: String::from("latest") }) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `server_type = Some(ServerType::Fabric { loader: v, installer: String::from("latest") });` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
}

if let Some(v) = value.get("quilt").cloned() {
server_type = Some(ServerType::Quilt { loader: v, installer: String::from("latest") })

Check warning on line 56 in src/api/models/server/server_type.rs

View workflow job for this annotation

GitHub Actions / clippy

consider adding a `;` to the last statement for consistent formatting

warning: consider adding a `;` to the last statement for consistent formatting --> src/api/models/server/server_type.rs:56:13 | 56 | server_type = Some(ServerType::Quilt { loader: v, installer: String::from("latest") }) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `server_type = Some(ServerType::Quilt { loader: v, installer: String::from("latest") });` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
}

if let Some(v) = value.get("quilt-loader").cloned() {
server_type = Some(ServerType::Quilt { loader: v, installer: String::from("latest") })

Check warning on line 60 in src/api/models/server/server_type.rs

View workflow job for this annotation

GitHub Actions / clippy

consider adding a `;` to the last statement for consistent formatting

warning: consider adding a `;` to the last statement for consistent formatting --> src/api/models/server/server_type.rs:60:13 | 60 | server_type = Some(ServerType::Quilt { loader: v, installer: String::from("latest") }) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `server_type = Some(ServerType::Quilt { loader: v, installer: String::from("latest") });` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
}

if let Some(v) = value.get("forge").cloned() {
server_type = Some(ServerType::Forge { loader: v })

Check warning on line 64 in src/api/models/server/server_type.rs

View workflow job for this annotation

GitHub Actions / clippy

consider adding a `;` to the last statement for consistent formatting

warning: consider adding a `;` to the last statement for consistent formatting --> src/api/models/server/server_type.rs:64:13 | 64 | server_type = Some(ServerType::Forge { loader: v }) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `server_type = Some(ServerType::Forge { loader: v });` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
}

if let Some(v) = value.get("neoforge").cloned() {
server_type = Some(ServerType::NeoForge { loader: v })

Check warning on line 68 in src/api/models/server/server_type.rs

View workflow job for this annotation

GitHub Actions / clippy

consider adding a `;` to the last statement for consistent formatting

warning: consider adding a `;` to the last statement for consistent formatting --> src/api/models/server/server_type.rs:68:13 | 68 | server_type = Some(ServerType::NeoForge { loader: v }) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `server_type = Some(ServerType::NeoForge { loader: v });` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
}

Ok(ServerJar {
mc_version: value.get("minecraft").ok_or(anyhow!("Can't resolve minecraft version"))?.clone(),
server_type: server_type.ok_or(anyhow!("Can't resolve a ServerType"))?,
})
}
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, JsonSchema)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum ServerType {
Expand Down
4 changes: 3 additions & 1 deletion src/api/models/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ impl Source {
pub async fn resolve_addons(&self, app: &App, relative_to: &Path) -> Result<Vec<Addon>> {
match &self.source_type {
SourceType::File { path } => {
let file: AddonListFile = read_toml(&with_extension_if_none(&relative_to.join(path), "toml")).with_context(|| format!("Source: File => {path}"))?;
let path = with_extension_if_none(&relative_to.join(path), "toml");
log::info!("Source: File => {path:?}");
let file: AddonListFile = read_toml(&path).with_context(|| format!("Source: File => {path:?}"))?;
Ok(file.flatten())
},

Expand Down
2 changes: 1 addition & 1 deletion src/api/sources/papermc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> PaperMCAPI<'a> {

let metadata = FileMeta {
cache: Some(CacheLocation(CACHE_DIR.into(), format!("{project}/{}", download.name))),
filename: download.name.clone(),
filename: String::from("server.jar"),
..Default::default()
};

Expand Down
2 changes: 1 addition & 1 deletion src/api/tools/java/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn check_java(path: &Path) -> Option<JavaInstallation> {

Some(JavaInstallation {
path,
version: JavaInstallation::get_version_from(info.get("java.version")?).ok()?,
version: JavaInstallation::parse_version(info.get("java.version")?).ok()?,
architecture: info.get("os.arch")?.clone(),
vendor: info.get("java.vendor")?.clone(),
})
Expand Down
2 changes: 1 addition & 1 deletion src/api/tools/java/installation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct JavaInstallation {
}

impl JavaInstallation {
pub fn get_version_from(version: &str) -> Result<JavaVersion> {
pub fn parse_version(version: &str) -> Result<JavaVersion> {
let mut split = version.split('.');

let str = match (split.next(), split.next()) {
Expand Down
31 changes: 21 additions & 10 deletions src/api/tools/java/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ pub type JavaVersion = u32;
mod installation;
mod find;
mod check;
use std::{path::Path, process::{ExitStatus, Stdio}};
use std::{ffi::OsStr, fmt::Debug, path::Path, process::{ExitStatus, Stdio}};

use anyhow::{anyhow, Result};
use anyhow::{anyhow, Context, Result};

Check warning on line 9 in src/api/tools/java/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `anyhow`

warning: unused import: `anyhow` --> src/api/tools/java/mod.rs:9:14 | 9 | use anyhow::{anyhow, Context, Result}; | ^^^^^^
pub use installation::*;
pub use check::*;
use tokio::{io::{AsyncBufReadExt, BufReader}, process::{Child, Command}};
Expand All @@ -18,23 +18,34 @@ pub struct JavaProcess {
}

impl JavaProcess {
pub fn new(
pub fn new<I: IntoIterator<Item = S1> + Debug, S1: AsRef<OsStr> + Debug, S2: AsRef<OsStr> + Debug>(
dir: &Path,
java: &Path,
args: &[&str],
java: S2,
args: I,
) -> Result<Self> {
// JRE is stupid
let dir = std::env::current_dir()?
.diff_to(dir)
.ok_or(anyhow!("Couldn't diff paths"))?;
let dir = if std::env::consts::OS == "windows" {
std::env::current_dir()?
.try_diff_to(dir)?
} else {
dir.to_path_buf()
};

let child = Command::new(java)
log::info!("Running java process");
log::info!("Cwd: {dir:?}");
log::info!("Java binary: {java:#?}");
log::info!("Arguments: {args:#?}");

let child = Command::new(&java)
.args(args)
.current_dir(dir)
.stderr(Stdio::inherit())
.stdout(Stdio::piped())
.stdin(Stdio::piped())
.spawn()?;
.spawn()
.with_context(|| format!("Spawning java process"))?;

Check failure on line 46 in src/api/tools/java/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

useless use of `format!`

error: useless use of `format!` --> src/api/tools/java/mod.rs:46:30 | 46 | .with_context(|| format!("Spawning java process"))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"Spawning java process".to_string()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format

log::info!("Child process spawned");

Ok(Self {
child,
Expand Down
4 changes: 2 additions & 2 deletions src/api/ws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ pub type WebsocketSink = SplitSink<WebSocketStream<TcpStream>, Message>;
pub type WebsocketStream = SplitStream<WebSocketStream<TcpStream>>;

Check warning on line 16 in src/api/ws/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

type alias `WebsocketStream` is never used

warning: type alias `WebsocketStream` is never used --> src/api/ws/mod.rs:16:10 | 16 | pub type WebsocketStream = SplitStream<WebSocketStream<TcpStream>>; | ^^^^^^^^^^^^^^^

pub struct WebsocketServer {
app: App,
app: Arc<App>,

Check warning on line 19 in src/api/ws/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

field `app` is never read

warning: field `app` is never read --> src/api/ws/mod.rs:19:5 | 18 | pub struct WebsocketServer { | --------------- field in this struct 19 | app: Arc<App>, | ^^^
clients: RwLock<Vec<WebsocketSink>>,
}

impl WebsocketServer {
pub fn new(app: App) -> Arc<Self> {
pub fn new(app: Arc<App>) -> Arc<Self> {
Arc::new(Self {
app,
clients: RwLock::new(vec![]),
Expand Down
Loading

0 comments on commit 3767d8e

Please sign in to comment.