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::epi::{App, Frame, Storage};
|
||||||
use eframe::NativeOptions;
|
use eframe::NativeOptions;
|
||||||
use env_logger::Env;
|
use env_logger::Env;
|
||||||
|
use log::info;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod graph;
|
pub mod graph;
|
||||||
|
@ -45,13 +48,15 @@ impl App for MetricsGui {
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
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() {
|
||||||
.set_title("Open a Bare Metrics Log")
|
PathBuf::from_str(path_arg)?
|
||||||
.add_filter("Bare Metrics Log", &["baremetrics"])
|
} else {
|
||||||
.pick_file()
|
rfd::FileDialog::new()
|
||||||
.expect("You must pick a file!");
|
.set_title("Open a Bare Metrics Log")
|
||||||
|
.add_filter("Bare Metrics Log", &["baremetrics"])
|
||||||
//let path = PathBuf::from_str(&std::env::args().skip(1).next().unwrap()).unwrap();
|
.pick_file()
|
||||||
|
.expect("You must pick a file!")
|
||||||
|
};
|
||||||
|
|
||||||
let file = File::open(path).unwrap();
|
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 filtered_log_app_name = log_app_name.to_lowercase().replace(' ', "_");
|
||||||
let dashboard_file = dashboard_dir.join(filtered_log_app_name + ".ron");
|
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 dashboard = if dashboard_file.exists() {
|
||||||
let rules_data: DashboardConfig = ron::de::from_reader(File::open(dashboard_file)?)?;
|
let rules_data: DashboardConfig = ron::de::from_reader(File::open(dashboard_file)?)?;
|
||||||
|
info!("Dashboard loaded successfully :)");
|
||||||
Some(rules_data)
|
Some(rules_data)
|
||||||
} else {
|
} else {
|
||||||
|
info!("No dashboard found.");
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue