feat: cli migrate to cobra with subcommands (#550)

* feat: migrate CLI to cobra with dump/list/version subcommands (#546)
* fix: remove residual duckduckgo references and add README/LICENSE to release archives
* fix: address PR review feedback from Copilot
This commit is contained in:
Roger
2026-04-05 14:25:51 +08:00
committed by GitHub
parent 068b82178f
commit 4af2ded428
15 changed files with 418 additions and 112 deletions
+25 -10
View File
@@ -16,19 +16,30 @@ import (
type Browser interface {
BrowserName() string
ProfileName() string
ProfileDir() string
Extract(categories []types.Category) (*types.BrowserData, error)
}
// PickBrowsers returns browsers matching the given name.
// When name is "all", all known browsers are tried.
// profilePath overrides the default user data directory (only when targeting a specific browser).
func PickBrowsers(name, profilePath string) ([]Browser, error) {
return pickFromConfigs(platformBrowsers(), name, profilePath)
// PickOptions configures which browsers to pick.
type PickOptions struct {
Name string // browser name filter: "all"|"chrome"|"firefox"|...
ProfilePath string // custom profile directory override
KeychainPassword string // macOS keychain password (ignored on other platforms)
}
// PickBrowsers returns browsers matching the given options.
// When Name is "all", all known browsers are tried.
// ProfilePath overrides the default user data directory (only when targeting a specific browser).
func PickBrowsers(opts PickOptions) ([]Browser, error) {
return pickFromConfigs(platformBrowsers(), opts)
}
// pickFromConfigs is the testable core of PickBrowsers.
func pickFromConfigs(configs []types.BrowserConfig, name, profilePath string) ([]Browser, error) {
name = strings.ToLower(name)
func pickFromConfigs(configs []types.BrowserConfig, opts PickOptions) ([]Browser, error) {
name := strings.ToLower(opts.Name)
if name == "" {
name = "all"
}
var browsers []Browser
for _, cfg := range configs {
@@ -36,14 +47,18 @@ func pickFromConfigs(configs []types.BrowserConfig, name, profilePath string) ([
continue
}
if profilePath != "" && name != "all" {
if opts.ProfilePath != "" && name != "all" {
if cfg.Kind == types.KindFirefox {
cfg.UserDataDir = filepath.Dir(filepath.Clean(profilePath))
cfg.UserDataDir = filepath.Dir(filepath.Clean(opts.ProfilePath))
} else {
cfg.UserDataDir = profilePath
cfg.UserDataDir = opts.ProfilePath
}
}
if opts.KeychainPassword != "" {
cfg.KeychainPassword = opts.KeychainPassword
}
bs, err := newBrowsers(cfg)
if err != nil {
log.Errorf("browser %s: %v", cfg.Name, err)