diff options
author | Alex Auvolat <alex@adnab.me> | 2024-04-03 20:10:26 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2024-04-03 20:10:26 +0200 |
commit | 3b8798e1dd52601f7837c30e97c6a7274344e446 (patch) | |
tree | 8d4c8f80841eaefa1a8711c67e80c2233073ae4a /src/main.rs | |
parent | 62e6641203f6af2c7ad90cace7fff045f867218e (diff) | |
download | datagengo-3b8798e1dd52601f7837c30e97c6a7274344e446.tar.gz datagengo-3b8798e1dd52601f7837c30e97c6a7274344e446.zip |
make server port configurable
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index c09d045..197ff24 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ extern crate log; use std::collections::HashMap; use std::fs; use std::io; +use std::net::SocketAddr; //use anyhow::Result; use rand::prelude::*; @@ -46,14 +47,17 @@ enum Cmd { Cleanup, AddVocab, Format, - Server, + Server { + #[structopt(default_value = "127.0.0.1:8080")] + bind_addr: SocketAddr, + }, } #[async_std::main] async fn main() { - if std::env::var("RUST_LOG").is_err() { - std::env::set_var("RUST_LOG", "datagengo=info") - } + if std::env::var("RUST_LOG").is_err() { + std::env::set_var("RUST_LOG", "datagengo=info") + } pretty_env_logger::init(); let opt = Opt::from_args(); @@ -82,7 +86,13 @@ async fn main() { ) .expect("parse_jmdict"); let jmdict_idx = index_jmdict(&jmdict); - fs::write("data/jmdict_idx.json", serde_json::to_string_pretty(&jmdict_idx).expect("to_json").as_bytes()).expect("write"); + fs::write( + "data/jmdict_idx.json", + serde_json::to_string_pretty(&jmdict_idx) + .expect("to_json") + .as_bytes(), + ) + .expect("write"); } Cmd::New { truncate, count } => { let kanji_levels = read_kanji_levels().expect("read_kanji_levels"); @@ -159,8 +169,10 @@ async fn main() { format_index(&batches, &kanji_levels).expect("format_index"); format_about().expect("format_about"); } - Cmd::Server => { - server::server_main().await.expect("error in server"); + Cmd::Server { bind_addr } => { + server::server_main(bind_addr) + .await + .expect("error in server"); } } } |