parent
29332b939e
commit
cd0b9bea93
@ -25,6 +25,7 @@ flexi_logger = "0.6.8"
|
|||||||
gdk-pixbuf = "0.2.0"
|
gdk-pixbuf = "0.2.0"
|
||||||
gdk-pixbuf-sys = "0.4.0"
|
gdk-pixbuf-sys = "0.4.0"
|
||||||
gdk-sys = "0.4.0"
|
gdk-sys = "0.4.0"
|
||||||
|
getopts = "0.2.15"
|
||||||
gio = "0.2.0"
|
gio = "0.2.0"
|
||||||
glib = "0.3.1"
|
glib = "0.3.1"
|
||||||
glib-sys = "0.4.0"
|
glib-sys = "0.4.0"
|
||||||
|
62
src/bin.rs
62
src/bin.rs
@ -1,22 +1,66 @@
|
|||||||
#![feature(alloc_system)]
|
#![feature(alloc_system)]
|
||||||
extern crate alloc_system;
|
extern crate alloc_system;
|
||||||
|
extern crate getopts;
|
||||||
|
|
||||||
extern crate pnmixerlib;
|
extern crate pnmixerlib;
|
||||||
|
|
||||||
use pnmixerlib::*;
|
use pnmixerlib::*;
|
||||||
|
|
||||||
use app_state::*;
|
use app_state::*;
|
||||||
|
use getopts::Options;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
gtk::init().unwrap();
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
flexi_logger::LogOptions::new()
|
let mut opts = Options::new();
|
||||||
.log_to_file(false)
|
opts.optflag("h", "help", "Show help");
|
||||||
// ... your configuration options go here ...
|
opts.optopt("", "log-to-file",
|
||||||
.init(Some("pnmixer=debug".to_string()))
|
"Log files to the specified dir instead of stderr",
|
||||||
.unwrap_or_else(|e| panic!("Logger initialization failed with {}", e));
|
"DIRECTORY");
|
||||||
|
opts.optflagopt("l", "log-level",
|
||||||
|
"Set the log level (trace/debug/info/warn/error/off)",
|
||||||
|
"LEVEL");
|
||||||
|
|
||||||
|
let matches = match opts.parse(&args[1..]) {
|
||||||
|
Ok(m) => { m }
|
||||||
|
Err(f) => { panic!(f.to_string()) }
|
||||||
|
};
|
||||||
|
|
||||||
|
if matches.opt_present("h") {
|
||||||
|
print_usage(opts);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let log_dir = matches.opt_str("log-to-file");
|
||||||
|
let log_level = matches.opt_default("log-level", "debug").map(|s| {
|
||||||
|
match s.to_lowercase().as_str() {
|
||||||
|
"trace" => flexi_logger::LogLevelFilter::Trace,
|
||||||
|
"debug" => flexi_logger::LogLevelFilter::Debug,
|
||||||
|
"info" => flexi_logger::LogLevelFilter::Info,
|
||||||
|
"warn" => flexi_logger::LogLevelFilter::Warn,
|
||||||
|
"error" => flexi_logger::LogLevelFilter::Error,
|
||||||
|
"off" => flexi_logger::LogLevelFilter::Off,
|
||||||
|
_ => flexi_logger::LogLevelFilter::Debug,
|
||||||
|
}
|
||||||
|
}).unwrap_or(flexi_logger::LogLevelFilter::Off);
|
||||||
|
|
||||||
|
let mut flogger = flexi_logger::Logger::with(
|
||||||
|
flexi_logger::LogSpecification::default(log_level).build());
|
||||||
|
|
||||||
|
if let Some(dir) = log_dir {
|
||||||
|
flogger = flogger.log_to_file().directory(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
flogger
|
||||||
|
.start()
|
||||||
|
.unwrap_or_else(|e|{panic!("Logger initialization failed with {}",e)});
|
||||||
|
|
||||||
|
|
||||||
|
gtk::init()
|
||||||
|
.unwrap_or_else(|e| panic!("Gtk initialization failed with {}", e));
|
||||||
|
|
||||||
let apps = Rc::new(new_alsa_appstate());
|
let apps = Rc::new(new_alsa_appstate());
|
||||||
|
|
||||||
@ -26,3 +70,9 @@ fn main() {
|
|||||||
|
|
||||||
// TODO: clean deallocation?
|
// TODO: clean deallocation?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn print_usage(opts: Options) {
|
||||||
|
let brief = format!("Usage: pnmixer-rs [options]");
|
||||||
|
print!("{}", opts.usage(&brief));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user