yukihirop/ultraman

Fix port option type

yukihirop opened this issue · 1 comments

Even though the default value is 5000, it was handled as Optional for some reason

#[structopt(name = "PORT", short = "p", long = "port")]
    pub port: Option<String>,

#[structopt(name = "PORT", short = "p", long = "port", default_value="5000")]
    pub port: String,

It was optional so that if an environment variable was specified, it could be prioritized.

fn base_port(env_path: PathBuf, port: Option<String>) -> String {
    let env = read_env(env_path).unwrap();
    let default_port = String::from("5000");

    if let Some(p) = port {
        p
    } else if let Some(p) = env.get("PORT") {
        p.clone()
    } else if let Ok(p) = os_env::var("PORT") {
        p
    } else {
        default_port
    }
}