diff options
| -rw-r--r-- | .env | 2 | ||||
| -rw-r--r-- | .env.example | 2 | ||||
| -rw-r--r-- | Cargo.toml | 4 | ||||
| -rw-r--r-- | src/main.rs | 46 |
4 files changed, 49 insertions, 5 deletions
@@ -1,5 +1,5 @@ # My personal .env file I use for development. ~ @fuwn -RUST_LOG=warn,whirl=info,whirl=debug #,whirl=trace +# RUST_LOG=warn,whirl=info,whirl=debug #,whirl=trace DATABASE_URL=sqlite:worlds.db WORLDSMASTER_GREETING="Welcome to Whirlsplash!" diff --git a/.env.example b/.env.example index ae22cf2..8cae026 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,3 @@ -RUST_LOG=trace +# RUST_LOG=trace DATABASE_URL= @@ -26,6 +26,10 @@ pretty_env_logger = "0.4.0" rand = "0.8.3" bytes = "1.0.1" +# CLI +structopt = "0.3.21" +clap = "3.0.0-beta.2" + # TCP [dependencies.tokio] version = "1.4.0" diff --git a/src/main.rs b/src/main.rs index 002bfe8..5489024 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,54 @@ use whirl::server::auto::server::AutoServer; use std::error::Error; use whirl::server::room::server::RoomServer; +use structopt::StructOpt; + +#[derive(StructOpt, Debug)] +enum Command { + Run, +} + +#[derive(StructOpt, Debug)] +#[structopt( + name = env!("CARGO_PKG_NAME"), + about = env!("CARGO_PKG_DESCRIPTION"), + version = env!("CARGO_PKG_VERSION"), + author = env!("CARGO_PKG_AUTHORS"), +)] +struct Opt { + #[structopt(short, long)] + debug: bool, + + #[structopt(short, long, parse(from_occurrences))] + verbose: u8, + + #[structopt(subcommand)] // help + command: Command, +} #[tokio::main] async fn main() -> Result<(), Box<dyn Error>> { + let opt = Opt::from_args(); + + // Set logging level + let mut log_level = "whirl=error,whirl=warn,whirl=info".to_string(); + if opt.debug { log_level += ",whirl=debug"; } + if opt.verbose >= 1 { log_level += ",whirl=trace"; }; + std::env::set_var("RUST_LOG", log_level); + + // Setup logging dotenv::dotenv().ok(); pretty_env_logger::init(); + // Handle CLI command + match opt.command { + Command::Run => run().await, + } + + Ok(()) +} + +async fn run() { let mut threads = vec![]; threads.push(tokio::spawn(async move { let _ = AutoServer::new("0.0.0.0:6650").await; @@ -17,6 +59,4 @@ async fn main() -> Result<(), Box<dyn Error>> { for thread in threads { let _ = thread.await; } - - Ok(()) -}
\ No newline at end of file +} |