Skip to content

Commit

Permalink
more api work
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlan404 committed May 29, 2024
1 parent 5acc9ac commit 943e11e
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 123 deletions.
51 changes: 51 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ tokio-util = { version = "0.7", features = ["io"] }
toml = "0.8"
walkdir = "2.4"
zip = "0.6"
cliclack = "0.2.5"
5 changes: 5 additions & 0 deletions src/api/app/actions/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::api::app::App;

impl App {

}
3 changes: 3 additions & 0 deletions src/api/app/actions/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod build;

pub use build::*;

Check warning on line 3 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:3:9 | 3 | pub use build::*; | ^^^^^^^^
27 changes: 27 additions & 0 deletions src/api/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
use std::sync::Arc;

use anyhow::{Context, Result};
use tokio::sync::RwLock;

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

pub mod actions;

pub const APP_USER_AGENT: &str = concat!(
env!("CARGO_PKG_NAME"),
Expand All @@ -10,6 +17,9 @@ pub const APP_USER_AGENT: &str = concat!(

pub struct App {
http_client: reqwest::Client,
server: Option<Arc<RwLock<Server>>>,
network: Option<Arc<RwLock<Network>>>,
ci: bool,
}

impl App {
Expand All @@ -21,6 +31,23 @@ impl App {

Ok(Self {
http_client,
server: None,
network: None,
ci: false,
})
}

pub async fn collect_addons(&self) -> Result<Vec<Addon>> {
let mut addons = vec![];

if let Some(lock) = &self.server {
let server = lock.read().await;

for source in &server.sources {
addons.append(&mut source.resolve().await?);
}
}

Ok(addons)
}
}
6 changes: 4 additions & 2 deletions src/api/models/addon.rs → src/api/models/addon/addon.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use anyhow::Result;

use crate::app::AddonType;
use crate::api::models::{Environment, Step};

use super::{Environment, Step};
use super::AddonType;

pub enum AddonTarget {
Plugin,
Mod,
Custom(String),
}

pub struct Addon {
pub environment: Option<Environment>,
pub addon_type: AddonType,
pub target: AddonTarget,
}

impl Addon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Result;
use serde::{Deserialize, Serialize};

use super::{ModpackSource, Addon};

use crate::api::models::ModpackSource;
use super::Addon;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum AddonSource {
Expand All @@ -20,7 +20,7 @@ pub enum AddonSource {
}

impl AddonSource {
async fn resolve(&self) -> Result<Vec<Addon>> {
pub async fn resolve(&self) -> Result<Vec<Addon>> {
Ok(vec![])
}
}
File renamed without changes.
7 changes: 7 additions & 0 deletions src/api/models/addon/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod addon;
mod addon_source;
mod addon_type;

pub use addon::*;
pub use addon_source::*;
pub use addon_type::*;
12 changes: 5 additions & 7 deletions src/api/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
mod server;
mod addon_source;
mod modpack_source;
mod step;
mod addon;
mod env;
mod packwiz;
mod mrpack;
mod hash;

pub mod addon;
pub mod packwiz;
pub mod mrpack;
pub mod network;

pub use server::*;
pub use addon_source::*;
pub use modpack_source::*;
pub use step::*;
pub use addon::*;
pub use env::*;
pub use packwiz::*;
pub use mrpack::*;
pub use hash::*;
3 changes: 3 additions & 0 deletions src/api/models/network/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub struct Network {

}
6 changes: 3 additions & 3 deletions src/api/models/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use super::AddonSource;
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
#[serde(default)]
pub struct Server {
name: String,
port: Option<i32>,
pub name: String,
pub port: Option<i32>,

sources: Vec<AddonSource>,
pub sources: Vec<AddonSource>,
}

impl Default for Server {
Expand Down
Empty file added src/api/sources/mod.rs
Empty file.
15 changes: 0 additions & 15 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
pub mod add;
pub mod build;
pub mod cache;
pub mod dev;
pub mod download;
pub mod eject;
pub mod env;
pub mod export;
pub mod import;
pub mod info;
pub mod init;
pub mod markdown;
pub mod pull;
pub mod run;
pub mod version;
pub mod world;
96 changes: 3 additions & 93 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
use anyhow::Result;
use app::BaseApp;
use api::app::App;
use clap::Parser;

mod api;
mod app;
mod commands;
mod core;
mod hot_reload;
mod interop;
mod model;
mod sources;
mod util;

use std::env;

#[derive(clap::Parser)]
#[clap(name = "mcman", version)]
Expand All @@ -27,96 +18,15 @@ struct Cli {

#[derive(clap::Subcommand)]
enum Commands {
/// Initialize a new mcman server
Init(commands::init::Args),

/// Build using server.toml configuration
Build(commands::build::BuildArgs),
/// Test the server (stops it when it ends startup)
Run(commands::run::RunArgs),
/// Start a development session
Dev(commands::dev::DevArgs),

/// Add a plugin/mod/datapack
#[command(subcommand)]
Add(commands::add::Commands),
/// Pull files from server/ to config/
Pull(commands::pull::Args),
/// Helpers for setting up the environment
#[command(subcommand)]
Env(commands::env::Commands),
/// Pack or unpack a world
#[command(subcommand, visible_alias = "w")]
World(commands::world::Commands),

/// Importing tools
#[command(subcommand, visible_alias = "i")]
Import(commands::import::Commands),
/// Exporting tools
#[command(subcommand)]
Export(commands::export::Commands),
/// Update markdown files with server info
#[command(visible_alias = "md")]
Markdown,

/// Download a downloadable
#[command(visible_alias = "dl")]
Download(commands::download::Args),
/// Cache management commands
#[command(subcommand)]
Cache(commands::cache::Commands),
/// Show info about the server in console
Info,
/// Show version information
#[command(visible_alias = "v")]
Version(commands::version::Args),

/// Eject - remove everything related to mcman
#[command(hide = true)]
Eject,
}

#[tokio::main]
async fn main() -> Result<()> {
if env::var("CI")
.map(|s| s.as_str() == "true")
.unwrap_or_default()
{
println!("::endgroup::");
}

let args = Cli::parse();
let base_app = BaseApp::new()?;
let app = App::new()?;

match args.command {
Commands::Init(args) => commands::init::run(base_app, args).await,
Commands::Cache(subcommands) => commands::cache::run(subcommands),
Commands::Version(args) => commands::version::run(base_app, args).await,
c => {
let mut app = base_app.upgrade()?;

match c {
// Build
Commands::Build(args) => commands::build::run(app, args).await,
Commands::Run(args) => commands::run::run(app, args).await,
Commands::Dev(args) => commands::dev::run(app, args).await,

// Management
Commands::Add(commands) => commands::add::run(app, commands).await,
Commands::Import(subcommands) => commands::import::run(app, subcommands).await,
Commands::Export(commands) => commands::export::run(app, commands).await,
Commands::Markdown => commands::markdown::run(app).await,
Commands::World(commands) => commands::world::run(&mut app, commands),
Commands::Pull(args) => commands::pull::run(&app, args),
Commands::Env(commands) => commands::env::run(&app, commands),
Commands::Eject => commands::eject::run(&app),

// Utils
Commands::Info => commands::info::run(&app),
Commands::Download(args) => commands::download::run(app, args).await,

_ => unreachable!(),
}
}
Commands::Init(args) => commands::init::run(app, args).await,
}
}

0 comments on commit 943e11e

Please sign in to comment.