Files
HackBrowserData/cmd/hack-browser-data/archive.go
T
Roger a734e777a8 refactor(app): export one function per command (#712)
* refactor(app): export one function per command

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.

* fix(app): check dumpkeys and archive -o up front

A missing output directory was reported only after the keys were retrieved or the files copied.

* docs(rfcs): move restore's input out of the command layer

Restore now discovers its directories in an archive itself, so the command layer no longer holds the data it reads.
2026-11-22 14:45:39 +08:00

42 lines
1.3 KiB
Go

package main
import (
"github.com/spf13/cobra"
"github.com/moond4rk/hackbrowserdata/internal/app"
"github.com/moond4rk/hackbrowserdata/internal/log"
)
func newArchiveCommand() *cobra.Command {
var flags app.ArchiveFlags
command := &cobra.Command{
Use: "archive",
Short: "Pack decryption-relevant profile files into a zip for cross-host restore",
Example: ` hack-browser-data archive
hack-browser-data archive -b chrome -c cookie -o chrome-cookies.zip`,
RunE: func(command *cobra.Command, args []string) error {
options, err := app.ValidateArchive(flags)
if err != nil {
return err
}
discovery, fileCount, err := app.Archive(command.Context(), options)
if err != nil {
return err
}
if len(discovery.Dirs) == 0 {
printNothingFound(command.ErrOrStderr(), discovery, "no browsers found")
return nil
}
log.Infof("Archived %d entries to %s", fileCount, options.ArchivePath)
return nil
},
}
command.Flags().StringVarP(&flags.Browser, "browser", "b", "all", "target browser: all|"+browserNames())
command.Flags().StringVarP(&flags.Categories, "category", "c", "all", "data categories (comma-separated): all|"+categoryNames())
command.Flags().StringVarP(&flags.OutputPath, "output", "o", "browser-data.zip", "output archive of decryption-relevant browser files")
return command
}