Skip to content

Conversation

@TeamDman
Copy link
Contributor

Adds support for specifying an initial file when launching the app from the terminal

❯ thoth .\my_github_stars.json

Copilot AI review requested due to automatic review settings January 11, 2026 19:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds command-line interface support to allow users to specify an initial file to open when launching Thoth from the terminal. The implementation adds basic CLI argument parsing for a --help flag and an optional file path argument.

Changes:

  • Added CLI argument parsing in main.rs to handle --help/-h flags and accept an optional file path
  • Modified ThothApp::new() to accept an optional initial file path parameter
  • Configured the window state to set the initial file path, which triggers automatic loading by the CentralPanel

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/main.rs Added CLI argument parsing logic to capture help flag and optional file path, then pass it to ThothApp
src/app/thoth_app.rs Updated constructor signature to accept optional initial file and set it in window state for automatic loading

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +44 to 53
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;
}

Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI argument parsing logic has a flaw: if multiple arguments are provided, only the first non-flag argument is captured as the file path, but any subsequent arguments are silently ignored without validation. This could confuse users who pass multiple file paths expecting them all to be opened or rejected with an error. Consider adding validation to detect and warn about unexpected additional arguments.

Suggested change
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;
}
let mut extra_args: Vec<std::ffi::OsString> = Vec::new();
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; any additional args are rejected
if cli_file.is_none() {
cli_file = Some(std::path::PathBuf::from(&arg));
} else {
extra_args.push(arg);
}
}
if !extra_args.is_empty() {
eprintln!("Error: unexpected additional argument(s): {:?}", extra_args);
eprintln!(
"Usage: 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 Err("Unexpected additional CLI arguments".into());
}

Copilot uses AI. Check for mistakes.
let mut cli_file: Option<std::path::PathBuf> = 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.");
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help message format is inconsistent with standard CLI conventions. The entire message is on a single line making it harder to read and maintain. Additionally, the em dash character (—) may not render properly in all terminal environments. Consider breaking this into multiple lines and using a regular hyphen for better compatibility.

Suggested change
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.");
println!(
"Thoth - JSON & NDJSON Viewer\n\
\n\
Usage: thoth [OPTIONS] [FILE]\n\
\n\
Options:\n\
-h, --help Show this help message\n\
\n\
If a FILE is supplied, Thoth will open it on startup."
);

Copilot uses AI. Check for mistakes.
cli_file = Some(std::path::PathBuf::from(arg));
break;
}

Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI parsing does not validate whether the provided file path exists or is accessible before passing it to the application. While the CentralPanel will eventually handle file opening errors, early validation here would provide a better user experience by giving immediate feedback if the file doesn't exist, rather than launching the GUI only to show an error. Consider adding a basic existence check and providing a meaningful error message on the command line.

Suggested change
// If a CLI file was provided, validate that it exists before launching the GUI
if let Some(ref path) = cli_file {
if !path.exists() {
eprintln!(
"Error: File '{}' does not exist or is not accessible.",
path.to_string_lossy()
);
return Err("CLI file path does not exist".into());
}
}

Copilot uses AI. Check for mistakes.
Comment on lines +42 to +52
// Parse simple CLI flags: --help / -h and optional FILE arg
let mut cli_file: Option<std::path::PathBuf> = 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;
}
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI file path argument lacks test coverage. Given that the codebase has comprehensive tests for other components, this new CLI functionality should have corresponding tests to verify proper argument parsing, help message output, and file path handling. Consider adding integration tests that validate the CLI argument parsing behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +46 to +50
// 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;
}
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial file handling logic directly sets the file_path without considering whether file_type needs to be determined. While the CentralPanel's file opening logic handles file type detection (lines 75-93 in central_panel.rs), it might be more explicit to document this dependency or ensure file_type is left as default when setting an initial file path. The current implementation relies on implicit default behavior which may not be immediately clear to future maintainers.

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Jan 11, 2026

Codecov Report

❌ Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 26.82%. Comparing base (8de9804) to head (65054f1).

Files with missing lines Patch % Lines
src/main.rs 0.00% 7 Missing ⚠️
src/app/thoth_app.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #59      +/-   ##
==========================================
- Coverage   26.87%   26.82%   -0.05%     
==========================================
  Files          58       58              
  Lines        5016     5025       +9     
==========================================
  Hits         1348     1348              
- Misses       3668     3677       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@anitnilay20
Copy link
Owner

Hey @TeamDman Thank you for the PR, i have already added the support for CLI to open files (#57), but I feel you have added more commands (I guess --help). Can you please update this branch and resolve conflicts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants