Basic config file
parent
e96f384b5e
commit
7552bc90a6
|
@ -26,6 +26,26 @@ version = "1.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "5.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dece029acd3353e3a58ac2e3eb3c8d6c35827a892edc6cc4138ef9c33df46ecd"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04414300db88f70d74c5ff54e50f9e1d1737d9a5b90f53fcf2e95ca2a9ab554b"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "forge-client"
|
||||
version = "0.1.0"
|
||||
|
@ -42,10 +62,12 @@ dependencies = [
|
|||
name = "forge-server"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"dirs",
|
||||
"paris",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"toml",
|
||||
"url",
|
||||
"uuid",
|
||||
"uuid-simd",
|
||||
|
@ -71,6 +93,12 @@ dependencies = [
|
|||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.2.6"
|
||||
|
@ -90,6 +118,16 @@ dependencies = [
|
|||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.6"
|
||||
|
@ -121,6 +159,12 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.8.6"
|
||||
|
@ -253,6 +297,17 @@ dependencies = [
|
|||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"redox_syscall",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.13"
|
||||
|
@ -296,6 +351,15 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.1"
|
||||
|
@ -332,6 +396,26 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.6.0"
|
||||
|
@ -377,6 +461,40 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b403acf6f2bb0859c93c7f0d967cb4a75a7ac552100f9322faf64dc047669b21"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.19.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.13"
|
||||
|
@ -531,3 +649,12 @@ name = "windows_x86_64_msvc"
|
|||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
|
|
@ -15,3 +15,4 @@ url = { version = "2.3.1", features = ["serde"]}
|
|||
uuid-simd = "0.8.0"
|
||||
uuid = { version = "1.3.0", features = ["v4", "fast-rng", "serde"] }
|
||||
paris = { version = "1.5", features = ["timestamps", "macros"] }
|
||||
toml = "0.7.3"
|
||||
|
|
|
@ -11,3 +11,5 @@ url.workspace = true
|
|||
uuid-simd.workspace = true
|
||||
uuid.workspace = true
|
||||
paris.workspace = true
|
||||
toml.workspace = true
|
||||
dirs = "5.0"
|
||||
|
|
|
@ -1,15 +1,24 @@
|
|||
use paris::{error, info, success};
|
||||
use paris::{error, info, success, warn};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Result;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
use std::net::SocketAddr;
|
||||
use std::{fmt, fs, io, net::SocketAddr, path::PathBuf, process::exit};
|
||||
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader};
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
use url::Url;
|
||||
use uuid::Uuid;
|
||||
use uuid_simd::UuidExt;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct HostConfig {
|
||||
ip: String,
|
||||
port: u16,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Config {
|
||||
host: HostConfig,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
enum BuildSystem {
|
||||
Cargo,
|
||||
|
@ -138,7 +147,8 @@ async fn process_socket(mut socket: TcpStream, address: SocketAddr) {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
let addr = "127.0.0.1:9134".to_string();
|
||||
let config = configure().await;
|
||||
let addr = format!("{}:{}", config.host.ip, config.host.port);
|
||||
let listener = TcpListener::bind(&addr).await?;
|
||||
info!("Listening on: <green>{}<//>", addr);
|
||||
|
||||
|
@ -153,3 +163,40 @@ async fn main() -> io::Result<()> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn configure() -> Config {
|
||||
let mut default_config = dirs::config_dir().unwrap();
|
||||
default_config.push("forge");
|
||||
default_config.push("config.toml");
|
||||
|
||||
let config_contents = match fs::read_to_string(&default_config) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
warn!("Unable to read from config file: {}", e);
|
||||
let config = Config {
|
||||
host: HostConfig {
|
||||
ip: "127.0.0.1".to_string(),
|
||||
port: 9134,
|
||||
},
|
||||
};
|
||||
let toml = toml::to_string(&config).unwrap();
|
||||
default_config.pop();
|
||||
fs::create_dir_all(&default_config).unwrap();
|
||||
default_config.push("config.toml");
|
||||
fs::write(&default_config, toml).unwrap();
|
||||
|
||||
info!("Created new config file at {}", &default_config.display());
|
||||
exit(0);
|
||||
}
|
||||
};
|
||||
|
||||
let config: Config = match toml::from_str(&config_contents) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
error!("Couldn't parse config file! {}", e);
|
||||
exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
return config;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue