Skip to content

refactor(app): export one function per command - #712

Open
moonD4rk wants to merge 3 commits into
mainfrom
refactor/app-commands
Open

moonD4rk wants to merge 3 commits into
mainfrom
refactor/app-commands

Conversation

@moonD4rk

@moonD4rk moonD4rk commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

Part of #710. Step 2 of 4.

internal/app exports one function per command. cmd parses flags, calls it, and prints what it returns.

Command Validate Run Returns
dump ValidateDump Dump Discovery, Summary
dumpkeys ValidateDumpKeys DumpKeys vault count
archive ValidateArchive Archive Discovery, file count
restore ValidateRestore Restore Discovery, Summary
list none, it has no flag to check List Discovery, Summary
  • Discovery and restore's handling of --data-dir and --data-zip move from cmd into these functions. Target, KeychainConfig, ListOptions, Execute, ExecuteWithKeys, CountRecords, and the exported Discover and DiscoverRestore are gone.
  • One convention for results: an error means the command could not run, and the other results are zero. A run that ended early, because it was stopped or its output could not be written, says so in the new Summary.Err, beside Result.Err and DirFailure.Err. Every command in cmd now checks err first, where each used to read the results before it in its own order.
  • cmd defines the shared flags once: addOutputFlags for dump and restore, and addPasswordFlags for the two password flag pairs.
  • snapshot.Unzip and Root.Path are removed, and restore unzips into its own temporary directory. snapshot.Open stays for the base packages' tests, which read a fixture directory in place.

One behavior change, in its own commit: dumpkeys -o and archive -o are checked before any work. A missing output directory used to be reported only after the keys were retrieved or the files copied. As a consequence, archive -o <missing dir>/a.zip now fails even when no browser is found.

RFC-001 no longer lists the data a restore reads among what the command layer holds.

Verification

  • Existing golden files are unchanged, and a full run with HBD_UPDATE_GOLDEN=1 rewrites none of them.
  • A binary built from main and one from this branch print the same, exit the same, and write the same files for 34 invocations: 18 with an empty home, and 16 with fixture data, including an output file that cannot be written.
  • New tests cover the early -o check, a rejected archive leaving no temporary directory behind, and a restore whose output cannot be written returning an error. Dropping return summary.Err from dump or restore fails a test.

Checklist

  • Pull request targets the main branch
  • All CI checks pass (lint, test, build)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • go.mod directive remains go 1.20 (do not bump)

Step 2 of #710. A command's logic was split between cmd and stage-shaped app calls; cmd now parses flags, calls one function and prints what it returns. An error means the command never ran, and a run that ended early says so in Summary.Err.
A missing output directory was reported only after the keys were retrieved or the files copied.
Restore now discovers its directories in an archive itself, so the command layer no longer holds the data it reads.
@moonD4rk moonD4rk added the refactor Code restructuring without changing external behavior label Nov 21, 2026
Copilot AI balanced review requested due to automatic review settings November 21, 2026 12:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

Labels

refactor Code restructuring without changing external behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants