aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-10-12 03:56:37 -0700
committerbnewbold <bnewbold@robocracy.org>2016-10-12 03:56:37 -0700
commit8d2bf9d3ccc6688281370812ed7d718f32f43ccd (patch)
tree21cc1e89d46d335ffdfc5905da68a5f7ef5acaad
parente298819227f038b9524085d49fb1446bd0b65482 (diff)
downloadeinhyrningsins-8d2bf9d3ccc6688281370812ed7d718f32f43ccd.tar.gz
einhyrningsins-8d2bf9d3ccc6688281370812ed7d718f32f43ccd.zip
refactor code around a small amount
-rw-r--r--src/main.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index 2765979..6f88878 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -474,15 +474,26 @@ fn main() {
ctrl_req_rx: ctrl_req_rx,
};
+ let path_str = matches.opt_str("socket-path").unwrap_or("/tmp/einhorn.sock".to_string());
+
if let Some(n) = matches.opt_str("number") {
cfg.count = u64::from_str(&n).expect("number arg should be an integer");
}
+ let bind_slugs = matches.opt_strs("bind");
+
+ let program_and_args = if !matches.free.is_empty() {
+ matches.free
+ } else {
+ println!("Missing program to run (try --help)");
+ exit(-1);
+ };
+
//// Bind Sockets
// Control socket first
- let ctrl_path = Path::new("/tmp/einhorn.sock");
// XXX: handle this more gracefully (per-process)
+ let ctrl_path = Path::new(&path_str);
if ctrl_path.exists() {
fs::remove_file(&ctrl_path).unwrap();
}
@@ -491,7 +502,7 @@ fn main() {
// XXX: set mode/permissions/owner?
// These will be tuples: (SocketAddr, SO_REUSEADDR, O_NONBLOCK)
- let sock_confs: Vec<(SocketAddr, bool, bool)> = matches.opt_strs("bind").iter().map(|b| {
+ let sock_confs: Vec<(SocketAddr, bool, bool)> = bind_slugs.iter().map(|b| {
let mut r = false;
let mut n = false;
let mut addr_chunks = b.split(',');
@@ -519,13 +530,6 @@ fn main() {
(sock, r, n)
}).collect();
- let program_and_args = if !matches.free.is_empty() {
- matches.free
- } else {
- print_usage(opts);
- exit(-1);
- };
-
let mut builder = env_logger::LogBuilder::new();
builder.parse("INFO");
if env::var("RUST_LOG").is_ok() {