From 65054f175681b2093be450154ce2dc5dcb01ef55 Mon Sep 17 00:00:00 2001 From: TeamDman Date: Sun, 11 Jan 2026 14:13:48 -0500 Subject: [PATCH] Add CLI to open file --- src/app/thoth_app.rs | 10 ++++++++-- src/main.rs | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/app/thoth_app.rs b/src/app/thoth_app.rs index b8be84a..e9ef1c0 100644 --- a/src/app/thoth_app.rs +++ b/src/app/thoth_app.rs @@ -32,8 +32,8 @@ pub struct ThothApp { } impl ThothApp { - /// Create a new ThothApp with loaded settings - pub fn new(settings: settings::Settings) -> Self { + /// Create a new ThothApp with loaded settings and optional initial file to open + pub fn new(settings: settings::Settings, initial_file: Option) -> Self { // Load persistent state (recent files, sidebar width, etc.) let persistent_state = PersistentState::default(); @@ -43,6 +43,12 @@ impl ThothApp { window_state.sidebar_expanded = persistent_state.get_sidebar_expanded(); } + // If an initial file was provided via CLI, set it so central panel will attempt to open it on first render + if let Some(path) = initial_file { + window_state.file_path = Some(path); + window_state.error = None; + } + // Initialize navigation history with configured size window_state.navigation_history = state::NavigationHistory::with_capacity(settings.performance.navigation_history_size); diff --git a/src/main.rs b/src/main.rs index 36d0bb1..10657a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,9 +39,17 @@ fn main() -> Result<()> { // Note: Settings mode is no longer supported // Settings are now opened via viewport mode from the main application // - // // Check if launched in settings mode - // let args: Vec = std::env::args().collect(); - // let is_settings_mode = args.iter().any(|arg| arg == "--settings"); + // Parse simple CLI flags: --help / -h and optional FILE arg + let mut cli_file: Option = None; + for arg in std::env::args_os().skip(1) { + if arg == std::ffi::OsString::from("--help") || arg == std::ffi::OsString::from("-h") { + println!("Thoth — JSON & NDJSON Viewer\n\nUsage: thoth [OPTIONS] [FILE]\n\nOptions:\n -h, --help Show this help message\n\nIf a FILE is supplied, Thoth will open it on startup."); + return Ok(()); + } + // First non-flag arg is treated as file path + cli_file = Some(std::path::PathBuf::from(arg)); + break; + } // Load settings first let settings = settings::Settings::load().unwrap_or_else(|e| { @@ -84,7 +92,7 @@ fn main() -> Result<()> { egui_phosphor::add_to_fonts(&mut fonts, egui_phosphor::Variant::Regular); cc.egui_ctx.set_fonts(fonts); - Ok(Box::new(app::ThothApp::new(settings))) + Ok(Box::new(app::ThothApp::new(settings, cli_file))) }), );