Config file can now be specified from command line

This commit is contained in:
Antoine Gersant 2016-09-23 01:39:55 -07:00
parent 0f2327ca4e
commit 07cb6cf648
7 changed files with 55 additions and 23 deletions

3
.gitignore vendored
View file

@ -1,4 +1,5 @@
target
release
*.dll
*.res
*.res
TestConfig.toml

6
Cargo.lock generated
View file

@ -2,6 +2,7 @@
name = "polaris"
version = "0.1.0"
dependencies = [
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)",
"id3 0.1.10 (git+https://github.com/jameshurst/rust-id3)",
"iron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -178,6 +179,11 @@ dependencies = [
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "getopts"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "hpack"
version = "0.2.0"

View file

@ -7,6 +7,7 @@ authors = ["Antoine Gersant <antoine.gersant@lesforges.org>"]
ui = []
[dependencies]
getopts = "0.2.14"
hyper = "0.9.10"
id3 = { git = "https://github.com/jameshurst/rust-id3" }
iron = "0.4.0"

View file

@ -1,16 +0,0 @@
auth_secret = 'Something very secret'
album_art_pattern = '^Folder\.(png|jpg|jpeg)$'
[[mount_dirs]]
name = 'root'
source = 'M:/Music/Genres/'
[[users]]
name = 'agersant'
password = 'test'
[ydns]
host = 'your_hostname.ydns.eu'
username = 'your_username'
password = 'your_ydns_password'

View file

@ -12,6 +12,7 @@ Remove-Item -Recurse .\release\windows\*
Copy-Item .\target\release\polaris.exe .\release\windows\
Copy-Item .\res\libeay32.dll .\release\windows\
Copy-Item .\res\libeay32md.dll .\release\windows\
Copy-Item .\res\SampleConfig.toml .\release\windows\Polaris.toml
Copy-Item .\Polaris.toml .\release\windows\
Copy-Item .\web\ .\release\windows\ -recurse

25
res/SampleConfig.toml Normal file
View file

@ -0,0 +1,25 @@
# Type anything here, don't leave the default
auth_secret = 'Something very secret'
# Pattern used to match album art matching a file
album_art_pattern = '^Folder\.(png|jpg|jpeg)$'
# Directories where your music is stored
[[mount_dirs]]
source = 'C:/Users/your_name/Music' # Location of the directory on your computer
name = 'root' # Public-facing name for this directory
# [[mount_dirs]]
# source = 'D:/more_music'
# name = 'extra'
# Users having access to the service
[[users]]
name = 'your_first_user'
password = 'your_first_password' # Passwords are stored unencrypted. Do not re-use a sensitive password!
# Use this section if you want Polaris to broadcast your IP to https://ydns.io
# [ydns]
# host = 'your_hostname.ydns.eu'
# username = 'your_username'
# password = 'your_ydns_password'

View file

@ -1,4 +1,5 @@
extern crate core;
extern crate getopts;
extern crate hyper;
extern crate id3;
extern crate iron;
@ -22,13 +23,13 @@ extern crate shell32;
#[cfg(windows)]
extern crate user32;
use std::path::Path;
use std::sync::Arc;
use std::sync::Mutex;
use getopts::Options;
use iron::prelude::*;
use mount::Mount;
use staticfile::Static;
use std::path;
use std::sync::Arc;
use std::sync::Mutex;
mod api;
mod collection;
@ -38,10 +39,23 @@ mod error;
mod ui;
mod vfs;
const DEFAULT_CONFIG_FILE_NAME: &'static str = "Polaris.toml";
fn main() {
// 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");
let matches = match options.parse(&args[1..]) {
Ok(m) => m,
Err(f) => panic!(f.to_string()),
};
let config_file_name = matches.opt_str("c").unwrap_or(DEFAULT_CONFIG_FILE_NAME.to_owned());
// Parse config
let config_file = Path::new("Polaris.toml");
println!("Reading configuration from {}", config_file_name);
let config_file = path::Path::new(config_file_name.as_str());
let config = config::Config::parse(&config_file).unwrap();
// Start server
@ -64,7 +78,7 @@ fn main() {
let mut mount = Mount::new();
mount.mount("/api/", api_chain);
mount.mount("/", Static::new(Path::new("web")));
mount.mount("/", Static::new(path::Path::new("web")));
let mut server = Iron::new(mount).http(("0.0.0.0", 5050)).unwrap();
// Start DDNS updates