Allow loading arg-specified paths without needing to ask
This commit is contained in:
parent
a0f85a4fdf
commit
a1208eed48
|
@ -6,7 +6,10 @@ use eframe::egui::{CentralPanel, CtxRef};
|
|||
use eframe::epi::{App, Frame, Storage};
|
||||
use eframe::NativeOptions;
|
||||
use env_logger::Env;
|
||||
use log::info;
|
||||
use std::fs::File;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
|
||||
pub mod config;
|
||||
pub mod graph;
|
||||
|
@ -45,13 +48,15 @@ impl App for MetricsGui {
|
|||
fn main() -> anyhow::Result<()> {
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
||||
|
||||
let path = rfd::FileDialog::new()
|
||||
let path = if let Some(path_arg) = &std::env::args().skip(1).next() {
|
||||
PathBuf::from_str(path_arg)?
|
||||
} else {
|
||||
rfd::FileDialog::new()
|
||||
.set_title("Open a Bare Metrics Log")
|
||||
.add_filter("Bare Metrics Log", &["baremetrics"])
|
||||
.pick_file()
|
||||
.expect("You must pick a file!");
|
||||
|
||||
//let path = PathBuf::from_str(&std::env::args().skip(1).next().unwrap()).unwrap();
|
||||
.expect("You must pick a file!")
|
||||
};
|
||||
|
||||
let file = File::open(path).unwrap();
|
||||
|
||||
|
@ -65,12 +70,14 @@ fn main() -> anyhow::Result<()> {
|
|||
|
||||
let filtered_log_app_name = log_app_name.to_lowercase().replace(' ', "_");
|
||||
let dashboard_file = dashboard_dir.join(filtered_log_app_name + ".ron");
|
||||
eprintln!("Looking for dashboard file at {:?}", dashboard_file);
|
||||
info!("Looking for dashboard file at {:?}", dashboard_file);
|
||||
|
||||
let dashboard = if dashboard_file.exists() {
|
||||
let rules_data: DashboardConfig = ron::de::from_reader(File::open(dashboard_file)?)?;
|
||||
info!("Dashboard loaded successfully :)");
|
||||
Some(rules_data)
|
||||
} else {
|
||||
info!("No dashboard found.");
|
||||
None
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue