-
Notifications
You must be signed in to change notification settings - Fork 227
/
main.rs
87 lines (74 loc) · 3.23 KB
/
main.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
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
81
82
83
84
85
86
87
use rumqttd::{Broker, Config};
use structopt::StructOpt;
#[derive(StructOpt)]
#[structopt(name = "rumqttd")]
#[structopt(about = "A high performance, lightweight and embeddable MQTT broker written in Rust.")]
#[structopt(author = "tekjar <raviteja@bytebeam.io>")]
struct CommandLine {
/// Binary version
#[structopt(skip = env!("VERGEN_BUILD_SEMVER"))]
version: String,
/// Build profile
#[structopt(skip= env!("VERGEN_CARGO_PROFILE"))]
profile: String,
/// Commit SHA
#[structopt(skip= env!("VERGEN_GIT_SHA"))]
commit_sha: String,
/// Commit SHA
#[structopt(skip= env!("VERGEN_GIT_COMMIT_TIMESTAMP"))]
commit_date: String,
/// path to config file
#[structopt(short, long)]
config: String,
/// log level (v: info, vv: debug, vvv: trace)
#[structopt(short = "v", long = "verbose", parse(from_occurrences))]
verbose: u8,
}
fn main() {
let commandline: CommandLine = CommandLine::from_args();
banner(&commandline);
let level = match commandline.verbose {
0 => "rumqttd=warn",
1 => "rumqttd=info",
2 => "rumqttd=debug",
_ => "rumqttd=trace",
};
// tracing syntac ->
let builder = tracing_subscriber::fmt()
.pretty()
.with_line_number(false)
.with_file(false)
.with_thread_ids(false)
.with_thread_names(false)
.with_env_filter(level)
.with_filter_reloading();
let reload_handle = builder.reload_handle();
builder
.try_init()
.expect("initialized subscriber succesfully");
let config = config::Config::builder()
.add_source(config::File::with_name(&commandline.config))
.build()
.unwrap();
let mut config: Config = config.try_deserialize().unwrap();
config.console.set_filter_reload_handle(reload_handle);
// println!("{:#?}", config);
let mut broker = Broker::new(config);
broker.start().unwrap();
}
fn banner(commandline: &CommandLine) {
const B: &str = r#"
██████╗ ██╗ ██╗███╗ ███╗ ██████╗ ████████╗████████╗██████╗
██╔══██╗██║ ██║████╗ ████║██╔═══██╗╚══██╔══╝╚══██╔══╝██╔══██╗
██████╔╝██║ ██║██╔████╔██║██║ ██║ ██║ ██║ ██║ ██║
██╔══██╗██║ ██║██║╚██╔╝██║██║▄▄ ██║ ██║ ██║ ██║ ██║
██║ ██║╚██████╔╝██║ ╚═╝ ██║╚██████╔╝ ██║ ██║ ██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚══▀▀═╝ ╚═╝ ╚═╝ ╚═════╝
"#;
println!("{}", B);
println!(" version: {}", commandline.version);
println!(" profile: {}", commandline.profile);
println!(" commit_sha: {}", commandline.commit_sha);
println!(" commit_date: {}", commandline.commit_date);
println!("\n");
}