feat(list): adds --delimiter flag to override default

This commit is contained in:
Lewis Wynne 2025-11-06 22:56:21 +00:00
parent 0b980ed9dc
commit 11cafdeb3d

View file

@ -56,6 +56,14 @@ func list(cmd *cobra.Command, args []string) error {
targetDB = "@" + dbName targetDB = "@" + dbName
} }
delimiter, err := cmd.Flags().GetString("delimiter")
if err != nil {
return err
}
if delimiter == "" {
delimiter = "\t\t"
}
trans := TransactionArgs{ trans := TransactionArgs{
key: targetDB, key: targetDB,
readonly: true, readonly: true,
@ -65,6 +73,7 @@ func list(cmd *cobra.Command, args []string) error {
if err != nil { if err != nil {
return err return err
} }
format := fmt.Sprintf("%%s%s%%s\n", delimiter)
opts := badger.DefaultIteratorOptions opts := badger.DefaultIteratorOptions
opts.PrefetchSize = 10 opts.PrefetchSize = 10
it := tx.NewIterator(opts) it := tx.NewIterator(opts)
@ -73,7 +82,7 @@ func list(cmd *cobra.Command, args []string) error {
item := it.Item() item := it.Item()
key := item.Key() key := item.Key()
if err := item.Value(func(v []byte) error { if err := item.Value(func(v []byte) error {
store.Print("%s\t\t%s\n", binary, key, v) store.Print(format, binary, key, v)
return nil return nil
}); err != nil { }); err != nil {
return err return err
@ -88,5 +97,6 @@ func list(cmd *cobra.Command, args []string) error {
func init() { func init() {
listCmd.Flags().BoolP("include-binary", "b", false, "include binary data in text output") listCmd.Flags().BoolP("include-binary", "b", false, "include binary data in text output")
listCmd.Flags().StringP("delimiter", "d", "\t\t", "string written between key and value columns")
rootCmd.AddCommand(listCmd) rootCmd.AddCommand(listCmd)
} }