Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlan404 committed Jun 2, 2024
1 parent 795ba47 commit ebdc857
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 5 deletions.
41 changes: 41 additions & 0 deletions src/api/app/actions/init/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::sync::Arc;

use anyhow::Result;
use cliclack::{input, intro};
use tokio::sync::RwLock;

use crate::api::{app::App, models::{network::Network, server::Server}};

impl App {
pub async fn init_server(&mut self) -> Result<()> {

Check warning on line 10 in src/api/app/actions/init/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

methods `init_server` and `init_network` are never used

warning: methods `init_server` and `init_network` are never used --> src/api/app/actions/init/mod.rs:10:18 | 9 | impl App { | -------- methods in this implementation 10 | pub async fn init_server(&mut self) -> Result<()> { | ^^^^^^^^^^^ ... 27 | pub async fn init_network(&mut self) -> Result<()> { | ^^^^^^^^^^^^
intro("initializing server")?;

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

let mut server = Server {

Check warning on line 16 in src/api/app/actions/init/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variable does not need to be mutable

warning: variable does not need to be mutable --> src/api/app/actions/init/mod.rs:16:13 | 16 | let mut server = Server { | ----^^^^^^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default
name,
port: None,
sources: vec![],
};

self.server = Some(Arc::new(RwLock::new(server)));

Ok(())
}

Check warning on line 25 in src/api/app/actions/init/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused `async` for function with no await statements

warning: unused `async` for function with no await statements --> src/api/app/actions/init/mod.rs:10:5 | 10 | / pub async fn init_server(&mut self) -> Result<()> { 11 | | intro("initializing server")?; 12 | | 13 | | let name: String = input("Name of the server?") ... | 24 | | Ok(()) 25 | | } | |_____^ | = help: consider removing the `async` from this function = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_async

pub async fn init_network(&mut self) -> Result<()> {
intro("initializing network")?;

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

let mut nw = Network {

Check warning on line 33 in src/api/app/actions/init/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variable does not need to be mutable

warning: variable does not need to be mutable --> src/api/app/actions/init/mod.rs:33:13 | 33 | let mut nw = Network { | ----^^ | | | help: remove this `mut`
name,
};

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

Ok(())
}

Check warning on line 40 in src/api/app/actions/init/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused `async` for function with no await statements

warning: unused `async` for function with no await statements --> src/api/app/actions/init/mod.rs:27:5 | 27 | / pub async fn init_network(&mut self) -> Result<()> { 28 | | intro("initializing network")?; 29 | | 30 | | let name: String = input("Name of the network?") ... | 39 | | Ok(()) 40 | | } | |_____^ | = help: consider removing the `async` from this function = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_async
}
2 changes: 2 additions & 0 deletions src/api/app/actions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod build;
mod init;

pub use build::*;

Check warning on line 4 in src/api/app/actions/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `build::*`

warning: unused import: `build::*` --> src/api/app/actions/mod.rs:4:9 | 4 | pub use build::*; | ^^^^^^^^
pub use init::*;

Check warning on line 5 in src/api/app/actions/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `init::*`

warning: unused import: `init::*` --> src/api/app/actions/mod.rs:5:9 | 5 | pub use init::*; | ^^^^^^^
2 changes: 1 addition & 1 deletion src/api/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use anyhow::{Context, Result};
use tokio::sync::RwLock;

use super::models::{network::Network, Addon, Server};
use super::models::{network::Network, Addon, server::Server};

pub mod actions;

Expand Down
3 changes: 1 addition & 2 deletions src/api/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod server;
mod modpack_source;
mod step;
mod env;
Expand All @@ -8,8 +7,8 @@ pub mod packwiz;
pub mod mrpack;
pub mod unsup;
pub mod network;
pub mod server;

pub use server::*;
pub use modpack_source::*;
pub use step::*;
pub use addon::*;
Expand Down
2 changes: 1 addition & 1 deletion src/api/models/network/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub struct Network {

pub name: String,
}
6 changes: 6 additions & 0 deletions src/api/models/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ use serde::{Serialize, Deserialize};

use super::AddonSource;

mod server_type;
mod server_flavor;

pub use server_type::*;

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

View workflow job for this annotation

GitHub Actions / clippy

unused import: `server_type::*`

warning: unused import: `server_type::*` --> src/api/models/server/mod.rs:8:9 | 8 | pub use server_type::*; | ^^^^^^^^^^^^^^
pub use server_flavor::*;

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

View workflow job for this annotation

GitHub Actions / clippy

unused import: `server_flavor::*`

warning: unused import: `server_flavor::*` --> src/api/models/server/mod.rs:9:9 | 9 | pub use server_flavor::*; | ^^^^^^^^^^^^^^^^

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
#[serde(default)]
pub struct Server {
Expand Down
34 changes: 34 additions & 0 deletions src/api/models/server/server_flavor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
pub enum ServerFlavor {
Vanilla,
Modded,
Patched,
Proxy,
}

impl ServerFlavor {
pub fn supports_datapacks(&self) -> bool {

Check warning on line 12 in src/api/models/server/server_flavor.rs

View workflow job for this annotation

GitHub Actions / clippy

this argument (1 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte)

warning: this argument (1 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> src/api/models/server/server_flavor.rs:12:31 | 12 | pub fn supports_datapacks(&self) -> bool { | ^^^^^ help: consider passing by value instead: `self` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref = note: `-W clippy::trivially-copy-pass-by-ref` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::trivially_copy_pass_by_ref)]`

Check warning on line 12 in src/api/models/server/server_flavor.rs

View workflow job for this annotation

GitHub Actions / clippy

methods `supports_datapacks`, `supports_mods`, and `supports_plugins` are never used

warning: methods `supports_datapacks`, `supports_mods`, and `supports_plugins` are never used --> src/api/models/server/server_flavor.rs:12:12 | 11 | impl ServerFlavor { | ----------------- methods in this implementation 12 | pub fn supports_datapacks(&self) -> bool { | ^^^^^^^^^^^^^^^^^^ ... 19 | pub fn supports_mods(&self) -> bool { | ^^^^^^^^^^^^^ ... 26 | pub fn supports_plugins(&self) -> bool { | ^^^^^^^^^^^^^^^^
match self {
ServerFlavor::Proxy => false,
_ => true,
}

Check failure on line 16 in src/api/models/server/server_flavor.rs

View workflow job for this annotation

GitHub Actions / clippy

match expression looks like `matches!` macro

error: match expression looks like `matches!` macro --> src/api/models/server/server_flavor.rs:13:9 | 13 | / match self { 14 | | ServerFlavor::Proxy => false, 15 | | _ => true, 16 | | } | |_________^ help: try: `!matches!(self, ServerFlavor::Proxy)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro = note: `-D clippy::match-like-matches-macro` implied by `-D clippy::all` = help: to override `-D clippy::all` add `#[allow(clippy::match_like_matches_macro)]`
}

pub fn supports_mods(&self) -> bool {

Check warning on line 19 in src/api/models/server/server_flavor.rs

View workflow job for this annotation

GitHub Actions / clippy

this argument (1 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte)

warning: this argument (1 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> src/api/models/server/server_flavor.rs:19:26 | 19 | pub fn supports_mods(&self) -> bool { | ^^^^^ help: consider passing by value instead: `self` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref
match self {
ServerFlavor::Modded => true,
_ => false,
}

Check failure on line 23 in src/api/models/server/server_flavor.rs

View workflow job for this annotation

GitHub Actions / clippy

match expression looks like `matches!` macro

error: match expression looks like `matches!` macro --> src/api/models/server/server_flavor.rs:20:9 | 20 | / match self { 21 | | ServerFlavor::Modded => true, 22 | | _ => false, 23 | | } | |_________^ help: try: `matches!(self, ServerFlavor::Modded)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro
}

pub fn supports_plugins(&self) -> bool {

Check warning on line 26 in src/api/models/server/server_flavor.rs

View workflow job for this annotation

GitHub Actions / clippy

this argument (1 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte)

warning: this argument (1 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> src/api/models/server/server_flavor.rs:26:29 | 26 | pub fn supports_plugins(&self) -> bool { | ^^^^^ help: consider passing by value instead: `self` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref
match self {
ServerFlavor::Vanilla => false,
ServerFlavor::Modded => false,

Check warning on line 29 in src/api/models/server/server_flavor.rs

View workflow job for this annotation

GitHub Actions / clippy

this match arm has an identical body to another arm

warning: this match arm has an identical body to another arm --> src/api/models/server/server_flavor.rs:29:13 | 29 | ServerFlavor::Modded => false, | --------------------^^^^^^^^^ | | | help: try merging the arm patterns: `ServerFlavor::Modded | ServerFlavor::Vanilla` | = help: or try changing either arm body note: other arm here --> src/api/models/server/server_flavor.rs:28:13 | 28 | ServerFlavor::Vanilla => false, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
ServerFlavor::Patched => true,

Check warning on line 30 in src/api/models/server/server_flavor.rs

View workflow job for this annotation

GitHub Actions / clippy

this match arm has an identical body to another arm

warning: this match arm has an identical body to another arm --> src/api/models/server/server_flavor.rs:30:13 | 30 | ServerFlavor::Patched => true, | ---------------------^^^^^^^^ | | | help: try merging the arm patterns: `ServerFlavor::Patched | ServerFlavor::Proxy` | = help: or try changing either arm body note: other arm here --> src/api/models/server/server_flavor.rs:31:13 | 31 | ServerFlavor::Proxy => true, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
ServerFlavor::Proxy => true,
}
}
}
73 changes: 73 additions & 0 deletions src/api/models/server/server_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use serde::{Deserialize, Serialize};
use crate::api::utils::serde::*;

Check warning on line 2 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:2:5 | 2 | use crate::api::utils::serde::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::api::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)]`

#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum BuildToolsFlavor {
#[default]
Spigot,
CraftBukkit,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum ServerType {
Vanilla {
mc_version: String,
},

PaperMC {
project: String,
#[serde(default = "str_latest")]
build: String,
},

Purpur {
#[serde(default = "str_latest")]
build: String,
},

Fabric {
#[serde(default = "str_latest")]
loader: String,

#[serde(default = "str_latest")]
installer: String,
},

Quilt {
#[serde(default = "str_latest")]
loader: String,

#[serde(default = "str_latest")]
installer: String,
},

NeoForge {
#[serde(default = "str_latest")]
loader: String,
},

Forge {
#[serde(default = "str_latest")]
loader: String,
},

BuildTools {
#[serde(default = "BuildToolsFlavor::default")]
software: BuildToolsFlavor,
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default = "Vec::new")]
args: Vec<String>,
},

Paper {},
Velocity {},
Waterfall {},
BungeeCord {},

Downloadable {
//#[serde(flatten)]
//inner: Downloadable,
},
}
1 change: 1 addition & 0 deletions src/api/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod hashing;
pub mod accessor;
pub mod serde;
3 changes: 3 additions & 0 deletions src/api/utils/serde.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn str_latest() -> String {
"latest".to_owned()
}
4 changes: 3 additions & 1 deletion src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub struct Args {



pub async fn run(app: App, args: Args) -> Result<()> {
pub async fn run(mut app: App, args: Args) -> Result<()> {

Check warning on line 14 in src/commands/init.rs

View workflow job for this annotation

GitHub Actions / clippy

variable does not need to be mutable

warning: variable does not need to be mutable --> src/commands/init.rs:14:18 | 14 | pub async fn run(mut app: App, args: Args) -> Result<()> { | ----^^^ | | | help: remove this `mut`

Check warning on line 14 in src/commands/init.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `args`

warning: unused variable: `args` --> src/commands/init.rs:14:32 | 14 | pub async fn run(mut app: App, args: Args) -> Result<()> { | ^^^^ help: if this is intentional, prefix it with an underscore: `_args`

Check warning on line 14 in src/commands/init.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `app`

warning: unused variable: `app` --> src/commands/init.rs:14:22 | 14 | pub async fn run(mut app: App, args: Args) -> Result<()> { | ^^^ help: if this is intentional, prefix it with an underscore: `_app`


Ok(())
}

Check warning on line 18 in src/commands/init.rs

View workflow job for this annotation

GitHub Actions / clippy

unused `async` for function with no await statements

warning: unused `async` for function with no await statements --> src/commands/init.rs:14:1 | 14 | / pub async fn run(mut app: App, args: Args) -> Result<()> { 15 | | 16 | | 17 | | Ok(()) 18 | | } | |_^ | = help: consider removing the `async` from this function = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_async

0 comments on commit ebdc857

Please sign in to comment.