aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd/web.rs
blob: 181ab7491e90f7c3a37c13f6db90bf863dc37575 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::prelude::*;

#[derive(serde::Deserialize, Debug, Default)]
pub struct Config {}

impl crate::config::Config for Config {
    fn merge_args<'a>(
        &mut self,
        _matches: &clap::ArgMatches<'a>,
    ) -> Result<()> {
        Ok(())
    }

    fn run(
        &self,
    ) -> Box<dyn futures::future::Future<Item = (), Error = Error> + Send>
    {
        let addr = "127.0.0.1:4145";
        Box::new(
            gotham::init_server(addr, crate::web::router())
                .map_err(|_| unreachable!()),
        )
    }
}

pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> {
    app.about("Run a teleterm web server")
}

pub fn config(
    config: Option<config::Config>,
) -> Result<Box<dyn crate::config::Config>> {
    let config: Config = if let Some(config) = config {
        config
            .try_into()
            .context(crate::error::CouldntParseConfig)?
    } else {
        Config::default()
    };
    Ok(Box::new(config))
}