fix(version): skip keys.json load for credential-free commands #31

Merged
David merged 1 commit from fix/version-no-keys-file-FJ-26 into main 2026-05-31 03:19:54 +02:00
Owner

Problem

main() loaded KeyInfo unconditionally before dispatching any subcommand. fj version and fj completion ignore credentials entirely, yet still triggered KeyInfo::load(), which prints keys file not found, creating to stderr on a fresh install:

fj version
keys file not found, creating
fj v0.7.1
Check for a new version with `fj version --check`

(load() only emits the notice and returns a default; it does not actually write the file, so the message is doubly misleading.)

Fix

Add Command::needs_keys() returning false for Version/Completion and true otherwise. main() now loads keys.json only when the dispatched command needs it; credential-free commands get KeyInfo::default(). The single dispatch site and all credential-using commands are unchanged.

Verification

  • XDG_DATA_HOME=$(mktemp -d) fj version prints only the version lines, emits no notice, and creates no keys.json.
  • cargo build, cargo fmt --check, cargo clippy -p forgejo-cli --all-targets all pass.

#FJ-26

## Problem `main()` loaded `KeyInfo` unconditionally before dispatching any subcommand. `fj version` and `fj completion` ignore credentials entirely, yet still triggered `KeyInfo::load()`, which prints `keys file not found, creating` to stderr on a fresh install: ``` fj version keys file not found, creating fj v0.7.1 Check for a new version with `fj version --check` ``` (`load()` only emits the notice and returns a default; it does not actually write the file, so the message is doubly misleading.) ## Fix Add `Command::needs_keys()` returning `false` for `Version`/`Completion` and `true` otherwise. `main()` now loads `keys.json` only when the dispatched command needs it; credential-free commands get `KeyInfo::default()`. The single dispatch site and all credential-using commands are unchanged. ## Verification - `XDG_DATA_HOME=$(mktemp -d) fj version` prints only the version lines, emits no notice, and creates no `keys.json`. - `cargo build`, `cargo fmt --check`, `cargo clippy -p forgejo-cli --all-targets` all pass. #FJ-26
fix(version): skip keys.json load for credential-free commands
All checks were successful
Check / fmt + clippy + build + tests (pull_request) Successful in 38s
Create release / Create release from merged PR (pull_request) Has been skipped
536b110bd4
`main()` loaded `KeyInfo` unconditionally before dispatching any subcommand, so `fj version` and `fj completion` triggered `KeyInfo::load()`, which prints `keys file not found, creating` on a fresh install even though neither command reads credentials.

Add `Command::needs_keys()` returning `false` for `Version`/`Completion`, and load `keys.json` in `main()` only when the dispatched command needs it; otherwise pass `KeyInfo::default()`. Credential-using commands are unchanged. Verified `fj version` against an empty `XDG_DATA_HOME` emits no notice and creates no file.

#FJ-26

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
David merged commit 324a549b35 into main 2026-05-31 03:19:54 +02:00
David deleted branch fix/version-no-keys-file-FJ-26 2026-05-31 03:19:54 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pandoras-box/forgejo-cli!31
No description provided.