Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
12c5a1f731
1 changed files with 25 additions and 7 deletions
32
src/main.rs
32
src/main.rs
|
@ -100,17 +100,34 @@ fn daemonize() -> Result<()> {
|
|||
|
||||
fn run() -> Result<()> {
|
||||
|
||||
#[cfg(unix)]
|
||||
daemonize()?;
|
||||
|
||||
// Parse CLI options
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
let mut options = Options::new();
|
||||
options.optopt("c", "config", "set the configuration file", "FILE");
|
||||
options.optopt("p", "port", "set polaris to run on a custom port", "PORT");
|
||||
options.optopt("d", "database", "set the path to index database", "FILE");
|
||||
options.optopt("w", "web", "set the path to web client files", "DIRECTORY");
|
||||
|
||||
#[cfg(unix)]
|
||||
options.optflag("f", "foreground", "run polaris in the foreground instead of daemonizing");
|
||||
|
||||
options.optflag("h", "help", "print this help menu");
|
||||
|
||||
let matches = options.parse(&args[1..])?;
|
||||
|
||||
if matches.opt_present("h") {
|
||||
let program = args[0].clone();
|
||||
let brief = format!("Usage: {} [options]", program);
|
||||
print!("{}", options.usage(&brief));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
//attribute inside the if clause, because they are not yet allowed on `if` expressions
|
||||
if !matches.opt_present("f") {
|
||||
#[cfg(unix)]
|
||||
daemonize()?;
|
||||
}
|
||||
|
||||
// Init DB
|
||||
println!("Starting up database");
|
||||
let db_path = matches.opt_str("d");
|
||||
|
@ -134,9 +151,9 @@ fn run() -> Result<()> {
|
|||
let index_sender = Arc::new(Mutex::new(index_sender));
|
||||
let db_ref = db.clone();
|
||||
std::thread::spawn(move || {
|
||||
let db = db_ref.deref();
|
||||
index::update_loop(db, index_receiver);
|
||||
});
|
||||
let db = db_ref.deref();
|
||||
index::update_loop(db, index_receiver);
|
||||
});
|
||||
|
||||
// Trigger auto-indexing
|
||||
let db_ref = db.clone();
|
||||
|
@ -161,7 +178,8 @@ fn run() -> Result<()> {
|
|||
mount.mount("/", Static::new(web_dir_path));
|
||||
|
||||
println!("Starting up server");
|
||||
let mut server = match Iron::new(mount).http(("0.0.0.0", 5050)) {
|
||||
let port: u16 = matches.opt_str("p").unwrap_or("5050".to_owned()).parse().or(Err("invalid port number"))?;
|
||||
let mut server = match Iron::new(mount).http(("0.0.0.0", port)) {
|
||||
Ok(s) => s,
|
||||
Err(e) => bail!("Error starting up server: {}", e),
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue