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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use std::ffi::OsString;

use eyre::eyre;
use filament_node::Config;
use tokio::runtime::Runtime;

use crate::{
    context::Context,
    terminal::{Args, Help},
};

pub const HELP: Help = Help {
    name: "node",
    description: "Run a filament node",
    version: env!("CARGO_PKG_VERSION"),
    usage: r#"
Usage

    flt node

Options

    --host <ip>
    --abci-port <port>
    --metrics-port <port>
    "#,
};

pub type Options = Config;

impl Args for Options {
    fn from_args(args: Vec<OsString>) -> eyre::Result<Self> {
        use lexopt::prelude::*;

        let mut parser = lexopt::Parser::from_args(args);
        let mut cfg = Config::default();

        while let Some(arg) = parser.next()? {
            match arg {
                Long("host") => {
                    cfg.host = parser
                        .value()?
                        .to_str()
                        .ok_or(eyre!("host is not UTF-8"))?
                        .to_owned();
                },
                Long("abci-port") => {
                    cfg.abci_port = parser
                        .value()?
                        .to_str()
                        .ok_or(eyre!("host is not UTF-8"))?
                        .to_owned();
                },
                Long("metrics-port") => {
                    cfg.metrics_port = parser
                        .value()?
                        .to_str()
                        .ok_or(eyre!("host is not UTF-8"))?
                        .to_owned();
                },
                _ => return Err(eyre!(arg.unexpected())),
            }
        }

        todo!()
    }
}

pub fn run(_ctx: Context, cfg: Options) -> eyre::Result<()> {
    let rt = Runtime::new()?;

    rt.block_on(filament_node::run(cfg))
}