summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
blob: c91b653279d08d5290fa0892cb9bdb5a04133ef0 (plain)
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
use std::path::PathBuf;

use structopt::StructOpt;
use anyhow::Error;

#[derive(Debug, StructOpt)]
#[structopt(name = "distrox", about = "Distrox - The distributed social network")]
pub struct CLI {
    #[structopt(short, long)]
    debug: bool,

    #[structopt(short, long)]
    trace: bool,

    #[structopt(short, long)]
    port: Option<u16>,

    #[structopt(parse(from_os_str))]
    configfile: Option<PathBuf>,

    #[structopt(subcommand)]
    cmd: Option<Command>
}

impl CLI {
    pub fn cmd(&self) -> Option<&Command> {
        self.cmd.as_ref()
    }

    pub fn port(&self) -> Option<u16> {
        self.port.as_ref().map(|p| *p)
    }
}

#[derive(Debug, PartialEq, StructOpt)]
#[structopt(about = "Start the server part (running in foreground")]
pub enum Command {
    Server,
}

pub fn cli() -> Result<CLI, Error> {
    Ok(CLI::from_args())
}