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
use std::env;
pub mod format;
use std::fs::OpenOptions;
use std::io::Write;
use std::path::PathBuf;
pub fn get_args() -> Vec<String> {
env::args().collect()
}
pub fn get_socket_path(socket_name: &str) -> String {
format!("/tmp/trigout/{}", socket_name)
}
pub fn get_socket_name(args: &[String]) -> String {
if args.len() < 2 {
return "0".to_owned();
}
args[1].clone()
}
pub fn write_to_file(path: PathBuf, c: &str) -> Result<(), std::io::Error> {
let file = OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open(path);
match file {
Ok(mut f) => f.write_all(format!("{}\n", c).as_bytes()),
Err(e) => Err(e),
}
}