-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.rs
51 lines (43 loc) · 1.25 KB
/
cli.rs
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
use anyhow::anyhow;
use clap::Parser;
use std::{path::PathBuf, str::FromStr};
#[derive(Parser, Debug)]
pub struct Cli {
/// mode for working, see enum WorkingMode
#[clap(short, long)]
#[clap(default_value = "local")]
pub mode: String,
/// config file path, used in local mode
#[clap(short, long)]
pub config: Option<PathBuf>,
/// interval for each data collection
#[clap(short, long)]
#[clap(default_value_t = 30)]
pub interval: u8,
/// connection string of the Iot Edge module,
/// used in iotedge mode, leave empty to use Iot Edge
/// environment variables
#[clap(long)]
#[clap(default_value = "")]
pub connection_string: String,
// TODO: detect the ip address automatically?
/// data collector ip address
#[clap(short, long)]
#[clap(default_value = "")]
pub src_ip_address: String,
}
#[derive(Clone, Debug)]
pub enum WorkingMode {
IotEdgeMode,
LocalMode,
}
impl FromStr for WorkingMode {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"iotedge" => Ok(Self::IotEdgeMode),
"local" => Ok(Self::LocalMode),
_ => Err(anyhow!("only iotedge and local mode are supported")),
}
}
}