Skip to content

fix(cli): handle --version/--help in the raw binary before Tauri boots - #403

Open
zichen0116 wants to merge 1 commit into
pacifio:mainfrom
zichen0116:fix/binary-version-flag
Open

zichen0116 wants to merge 1 commit into
pacifio:mainfrom
zichen0116:fix/binary-version-flag

Conversation

@zichen0116

@zichen0116 zichen0116 commented Oct 11, 2026 •

Copy link
Copy Markdown

Problem

tryatlas --version opens the full application window instead of printing a version and exiting (issue #371). The shell helper (~/.local/bin/atlas) intercepts --version|-v / --help|-h itself, but invoking the raw binary directly has no such interception: run() calls parse_initial_project(), which returns None for flag-like args, and Tauri boots the GUI.

Fix

Intercept the first argv flag in run() before Tauri starts:

  • src-tauri/src/commands/cli.rs: new EarlyCliFlag enum + pure early_cli_flag() matcher (first argv slot only, --version|-v / --help|-h, mirroring the shell helper's spellings), CLI_HELP usage text mirroring the helper, and handle_early_cli_flags() which prints atlas <CARGO_PKG_VERSION> (0.4.0, the same source the helper bakes into its --version branch) or the usage text and exits 0.
  • src-tauri/src/lib.rs: call handle_early_cli_flags() immediately before parse_initial_project() in run().

Only the first argument is inspected, consistent with the shell helper checking $1; atlas <path> --version still goes through the existing positional-path handling.

Verification

  • Added #[cfg(test)] unit tests for early_cli_flag covering all four flags, empty args, non-flag args, flag-in-second-position, unknown flags, and --version=x.
  • The pure matcher was extracted verbatim and compiled/run standalone with rustc 1.99: all 14 assertions pass (the full cargo test target needs the Tauri GUI dependency graph, which isn't buildable in this environment).
  • rustfmt --check clean; git diff --check clean.

Closes #371

Summary by CodeRabbit

  • New Features
    • Added command-line --version/-v and --help/-h options, displayed before the app starts.

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5bab393a-4d4c-4a56-956c-05dfcac00a45

📥 Commits

Reviewing files that changed from the base of the PR and between bb8eb6a and 9a8ab94.


📒 Files selected for processing (2)
  • src-tauri/src/commands/cli.rs
  • src-tauri/src/lib.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.



📝 Walkthrough

Walkthrough

The binary now handles --version/-v and --help/-h before project-path parsing and Tauri startup. Other arguments continue through the existing startup path.

Changes

Early CLI flags

Layer / File(s) Summary
Recognize and handle early flags
src-tauri/src/commands/cli.rs, src-tauri/src/lib.rs
The CLI recognizes version and help aliases only when they are the first argument. For recognized flags, it prints the version or usage text and exits successfully. Tests cover supported aliases and ignored argument forms. The run path checks these flags before project-path parsing and Tauri startup.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: pacifio


Merge Risk | ⚪ Minimal · up to 9a8ab

Merge Risk: ⚪ Minimal · up to 9a8ab

Help and version requests exit before project parsing and Tauri startup. Logging setup may create a directory, but an unwritable directory does not block these requests; no material merge risk remains.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to 9a8ab

The supported flags produce fixed help or version text and terminate before application startup. The change does not grant additional authority, open a project, or modify an already-running instance.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The new branch affects the invoking process. It exits before single-instance registration, so recognized help/version requests cannot use that branch to forward project arguments, focus a window, or emit events into an already-running instance.

Trust Boundaries and Controls

  • observed — Caller-controlled argv selects between fixed responses and normal startup. The new branch does not interpolate supplied arguments into output, execute a command, access a supplied project path, or delegate authority.

Resilience and Maintainability Implications

  • observed — Logging may create a directory and file before early termination. These side effects already occurred before the inserted handler; directory-creation failure disables file logging rather than preventing the handler from being reached.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: handling --version and --help before Tauri starts in the raw binary.
Linked Issues check Passed Issue [#371] requires the raw binary to handle --version before project-path parsing and to avoid launching the GUI. early_cli_flag() matches --version/-v and --help/-h only in the first a…
Out of Scope Changes check Passed The reported pull request changes are limited to early CLI flag matching, version/help output, related unit tests, and the call site in run(). These changes directly support issue [#371]. The first-…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

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.

--version boots the full GUI instead of printing the version

1 participant