diff options
| author | Fuwn <[email protected]> | 2021-03-29 12:51:00 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-03-29 12:51:00 +0000 |
| commit | cc5e4c2ebcda70f2fbd2a5a668adfa8066aeadc7 (patch) | |
| tree | ef6b7884518ed7a5d97baaae6ddcf8cfb7e5cc20 /src/main.rs | |
| parent | chore: Change Rust toolchain for more accurate reproducibility (diff) | |
| download | whirl-cc5e4c2ebcda70f2fbd2a5a668adfa8066aeadc7.tar.xz whirl-cc5e4c2ebcda70f2fbd2a5a668adfa8066aeadc7.zip | |
feature: Implement CLI
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 46 |
1 files changed, 43 insertions, 3 deletions
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 +} |