diff --git a/cmd/export.go b/cmd/export.go index bdfd28d..ff27e22 100644 --- a/cmd/export.go +++ b/cmd/export.go @@ -43,6 +43,5 @@ var exportCmd = &cobra.Command{ func init() { exportCmd.Flags().StringSliceP("glob", "g", nil, "Filter keys with glob pattern (repeatable)") exportCmd.Flags().String("glob-sep", "", fmt.Sprintf("Characters treated as separators for globbing (default %q)", defaultGlobSeparatorsDisplay())) - exportCmd.Flags().StringVarP(&listEncoding, "encoding", "e", "auto", "value encoding: auto, base64, or text") rootCmd.AddCommand(exportCmd) } diff --git a/cmd/list.go b/cmd/list.go index 6562aa8..88779f4 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -23,14 +23,12 @@ THE SOFTWARE. package cmd import ( - "encoding/base64" "encoding/json" "errors" "fmt" "io" "os" "strconv" - "unicode/utf8" "github.com/jedib0t/go-pretty/v6/table" "github.com/jedib0t/go-pretty/v6/text" @@ -60,9 +58,8 @@ var ( listNoKeys bool listNoValues bool listTTL bool - listHeader bool - listFormat formatEnum = "table" - listEncoding string + listHeader bool + listFormat formatEnum = "table" ) type columnKind int @@ -155,16 +152,8 @@ func list(cmd *cobra.Command, args []string) error { // NDJSON format: emit JSON lines directly if listFormat.String() == "ndjson" { - enc := listEncoding - if enc == "" { - enc = "auto" - } for _, e := range filtered { - je, err := encodeJsonEntryWithEncoding(e, enc) - if err != nil { - return fmt.Errorf("cannot ls '%s': %v", targetDB, err) - } - data, err := json.Marshal(je) + data, err := json.Marshal(encodeJsonEntry(e)) if err != nil { return fmt.Errorf("cannot ls '%s': %v", targetDB, err) } @@ -310,33 +299,6 @@ func renderTable(tw table.Writer) { } } -// encodeJsonEntryWithEncoding encodes an Entry to jsonEntry respecting the encoding mode. -func encodeJsonEntryWithEncoding(e Entry, mode string) (jsonEntry, error) { - switch mode { - case "base64": - je := jsonEntry{Key: e.Key, Encoding: "base64"} - je.Value = base64.StdEncoding.EncodeToString(e.Value) - if e.ExpiresAt > 0 { - ts := int64(e.ExpiresAt) - je.ExpiresAt = &ts - } - return je, nil - case "text": - if !utf8.Valid(e.Value) { - return jsonEntry{}, fmt.Errorf("key %q contains non-UTF8 data; use --encoding=auto or base64", e.Key) - } - je := jsonEntry{Key: e.Key, Encoding: "text"} - je.Value = string(e.Value) - if e.ExpiresAt > 0 { - ts := int64(e.ExpiresAt) - je.ExpiresAt = &ts - } - return je, nil - default: // "auto" - return encodeJsonEntry(e), nil - } -} - func init() { listCmd.Flags().BoolVarP(&listBinary, "binary", "b", false, "include binary data in text output") listCmd.Flags().BoolVar(&listNoKeys, "no-keys", false, "suppress the key column") @@ -346,6 +308,5 @@ func init() { listCmd.Flags().VarP(&listFormat, "format", "o", "output format (table|tsv|csv|markdown|html|ndjson)") listCmd.Flags().StringSliceP("glob", "g", nil, "Filter keys with glob pattern (repeatable)") listCmd.Flags().String("glob-sep", "", fmt.Sprintf("Characters treated as separators for globbing (default %q)", defaultGlobSeparatorsDisplay())) - listCmd.Flags().StringVarP(&listEncoding, "encoding", "e", "auto", "value encoding for ndjson format: auto, base64, or text") rootCmd.AddCommand(listCmd) } diff --git a/testdata/help__dump__ok.ct b/testdata/help__dump__ok.ct index 2bcce3b..db48321 100644 --- a/testdata/help__dump__ok.ct +++ b/testdata/help__dump__ok.ct @@ -9,7 +9,6 @@ Aliases: export, dump Flags: - -e, --encoding string value encoding: auto, base64, or text (default "auto") -g, --glob strings Filter keys with glob pattern (repeatable) --glob-sep string Characters treated as separators for globbing (default "/-_.@: ") -h, --help help for export @@ -22,7 +21,6 @@ Aliases: export, dump Flags: - -e, --encoding string value encoding: auto, base64, or text (default "auto") -g, --glob strings Filter keys with glob pattern (repeatable) --glob-sep string Characters treated as separators for globbing (default "/-_.@: ") -h, --help help for export diff --git a/testdata/help__list__ok.ct b/testdata/help__list__ok.ct index b8b5af3..f9f51ed 100644 --- a/testdata/help__list__ok.ct +++ b/testdata/help__list__ok.ct @@ -10,7 +10,6 @@ Aliases: Flags: -b, --binary include binary data in text output - -e, --encoding string value encoding for ndjson format: auto, base64, or text (default "auto") -o, --format format output format (table|tsv|csv|markdown|html|ndjson) (default table) -g, --glob strings Filter keys with glob pattern (repeatable) --glob-sep string Characters treated as separators for globbing (default "/-_.@: ") @@ -29,7 +28,6 @@ Aliases: Flags: -b, --binary include binary data in text output - -e, --encoding string value encoding for ndjson format: auto, base64, or text (default "auto") -o, --format format output format (table|tsv|csv|markdown|html|ndjson) (default table) -g, --glob strings Filter keys with glob pattern (repeatable) --glob-sep string Characters treated as separators for globbing (default "/-_.@: ")