add docker container creation (add broken since sqlite change)
This commit is contained in:
18
src/main.rs
18
src/main.rs
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/29 21:22:17 by tomoron #+# #+# */
|
||||
/* Updated: 2026/06/06 19:39:47 by tomoron ### ########.fr */
|
||||
/* Updated: 2026/06/09 00:05:23 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -20,7 +20,7 @@ pub mod models;
|
||||
|
||||
pub mod status;
|
||||
|
||||
pub mod docker;
|
||||
pub mod dockermgr;
|
||||
|
||||
mod cli;
|
||||
use cli::*;
|
||||
@ -28,20 +28,22 @@ use cli::*;
|
||||
mod config;
|
||||
pub use config::Config;
|
||||
|
||||
use clap::Command;
|
||||
|
||||
pub type DbPool = Pool<ConnectionManager<SqliteConnection>>;
|
||||
|
||||
use bollard::Docker;
|
||||
|
||||
fn get_connection_pool() -> DbPool {
|
||||
let database_url = "sqlite:///".to_string() + &Config::load().config_path + "/db.sqlite";
|
||||
let database_url = "sqlite://".to_string() + &Config::load().config_path + "/db.sqlite";
|
||||
|
||||
let manager = ConnectionManager::<SqliteConnection>::new(&database_url);
|
||||
Pool::builder()
|
||||
.build(manager)
|
||||
.unwrap_or_else(|_| panic!("Error creating pool for {}", database_url))
|
||||
.unwrap_or_else(|e| panic!("Error creating pool for {}\nerror: {:?}", database_url, e))
|
||||
}
|
||||
|
||||
|
||||
use clap::Command;
|
||||
|
||||
fn cli() -> Command {
|
||||
Command::new("dmm")
|
||||
.about("Docker Minecraft server Manager cli")
|
||||
@ -56,12 +58,14 @@ fn cli() -> Command {
|
||||
.subcommand(remove::create_subcommand())
|
||||
.subcommand(edit::create_subcommand())
|
||||
.subcommand(ls::create_subcommand())
|
||||
.subcommand(start::create_subcommand())
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() -> Result<(), String> {
|
||||
let arg = cli().get_matches();
|
||||
let pool = get_connection_pool();
|
||||
let docker = Docker::connect_with_defaults().expect("Failed to connect to local docker");
|
||||
|
||||
match arg.subcommand() {
|
||||
Some(("serverMode", _)) => { mc_socket_listen(pool).await.map_err(|_| "socket error".to_string())?; },
|
||||
@ -69,6 +73,8 @@ async fn main() -> Result<(), String> {
|
||||
Some(("remove", sub_matches)) => { remove::subcommand(sub_matches, pool).await?; },
|
||||
Some(("ls", sub_matches)) => { ls::subcommand(sub_matches, pool).await?; },
|
||||
Some(("edit", sub_matches)) => { edit::subcommand(sub_matches, pool).await?; },
|
||||
|
||||
Some(("start", sub_matches)) => { start::subcommand(sub_matches, &pool, docker).await?; },
|
||||
_ => {panic!("subcommand not implemented")}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user