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
74
75
76
77
78
79
80
use crate::trace;
use clap::Parser;
use std::str::FromStr;
#[derive(Clone, Debug)]
pub enum RestartPolicy {
Never,
Always,
}
impl FromStr for RestartPolicy {
type Err = String;
fn from_str(code: &str) -> Result<Self, Self::Err> {
match code {
"never" => Ok(RestartPolicy::Never),
"always" => Ok(RestartPolicy::Always),
_ => Err("Could not parse input as RestartPolicy".to_string()),
}
}
}
#[derive(Clone, Debug)]
pub enum LoggingFormat {
Full,
Json,
}
impl Default for LoggingFormat {
fn default() -> Self {
LoggingFormat::Full
}
}
impl FromStr for LoggingFormat {
type Err = String;
fn from_str(code: &str) -> Result<Self, Self::Err> {
match code {
"full" => Ok(LoggingFormat::Full),
"json" => Ok(LoggingFormat::Json),
_ => Err("Could not parse input as LoggingFormat".to_string()),
}
}
}
impl LoggingFormat {
pub fn init_subscriber(&self) {
match *self {
Self::Full => trace::init_subscriber(),
Self::Json => trace::init_json_subscriber(),
}
}
}
#[derive(Parser, Debug, Clone)]
pub struct ServiceConfig {
#[clap(long, default_value = "always")]
pub restart_policy: RestartPolicy,
#[clap(long, default_value = "full")]
pub logging_format: LoggingFormat,
}
#[derive(Parser, Debug, Clone)]
pub struct MonitoringConfig {
#[clap(long)]
pub no_prometheus: bool,
#[clap(long)]
pub prometheus_external: bool,
#[clap(long, default_value = "9615")]
pub prometheus_port: u16,
}