fix(restore): polish help text, drop dead check, dedup dump kinds

pflag treats backticked words in flag usage as the value placeholder,
so --data-zip rendered as "--data-zip archive" in help output.
This commit is contained in:
moonD4rk
2026-06-10 10:48:23 +08:00
parent 6d0efadb59
commit 72a046c4d6
2 changed files with 12 additions and 15 deletions
+11 -11
View File
@@ -174,19 +174,19 @@ func retrieversFromKeys(mk masterkey.MasterKeys) masterkey.Retrievers {
}
}
func kindToDump(k types.BrowserKind) (string, error) {
switch k {
case types.Chromium, types.ChromiumYandex, types.ChromiumOpera:
return k.String(), nil
default:
return "", fmt.Errorf("engine kind %s is not exportable", k)
}
}
// dumpableKinds are the engine kinds a vault may carry; kindFromDump reverses BrowserKind.String()
// over exactly these, keeping the wire vocabulary single-sourced in the types enum.
// dumpableKinds are the engine kinds a vault may carry; kindToDump/kindFromDump translate to and from
// the wire form via BrowserKind.String(), keeping the vocabulary single-sourced in the types enum.
var dumpableKinds = []types.BrowserKind{types.Chromium, types.ChromiumYandex, types.ChromiumOpera}
func kindToDump(k types.BrowserKind) (string, error) {
for _, dk := range dumpableKinds {
if k == dk {
return k.String(), nil
}
}
return "", fmt.Errorf("engine kind %s is not exportable", k)
}
func kindFromDump(s string) (types.BrowserKind, error) {
for _, k := range dumpableKinds {
if k.String() == s {
+1 -4
View File
@@ -57,7 +57,7 @@ func restoreCmd() *cobra.Command {
cmd.Flags().StringVar(&keysPath, "keys", "", "keys file from dumpkeys (use - for stdin)")
cmd.Flags().StringVar(&dataDir, "data-dir", "", "copied profile data dir (archive layout, or one browser's User Data with -b)")
cmd.Flags().StringVar(&dataZip, "data-zip", "", "archive zip from `archive` (alternative to --data-dir)")
cmd.Flags().StringVar(&dataZip, "data-zip", "", "zip produced by the archive command (alternative to --data-dir)")
cmd.Flags().StringVarP(&browserName, "browser", "b", "", "restore only this browser (optional; must match a vault in --keys)")
cmd.Flags().StringVarP(&category, "category", "c", "all", "data categories (comma-separated): all|"+categoryNames())
cmd.Flags().StringVarP(&outputFormat, "format", "f", "json", "output format: csv|json|cookie-editor")
@@ -74,9 +74,6 @@ func loadRestoreBrowsers(keysPath, dataDir, browserName string) ([]browser.Brows
if keysPath == "" {
return nil, fmt.Errorf("requires --keys <file> (or - for stdin)")
}
if dataDir == "" {
return nil, fmt.Errorf("requires --data-dir <dir>")
}
var r io.Reader = os.Stdin
if keysPath != "-" {