@@ -3,12 +3,12 @@ package main
3
3
import (
4
4
"bufio"
5
5
"fmt"
6
+ "io"
6
7
"log"
7
8
"os"
8
9
"strings"
9
10
10
11
kval "github.com/kval-access-language/kval-boltdb"
11
- "github.com/olekukonko/tablewriter"
12
12
"github.com/urfave/cli"
13
13
)
14
14
@@ -19,6 +19,7 @@ const goingBack = "> Going back..."
19
19
func main () {
20
20
var file string
21
21
var noValues bool
22
+ var useMore bool
22
23
23
24
cli .AppHelpTemplate = `NAME:
24
25
{{.Name}} - {{.Usage}}
@@ -59,17 +60,29 @@ COPYRIGHT:
59
60
Usage : "use if values are huge and/or not printable" ,
60
61
Destination : & noValues ,
61
62
},
63
+ & cli.BoolFlag {
64
+ Name : "more" ,
65
+ Usage : "use `more` to print all listings. Should be available in path" ,
66
+ Destination : & useMore ,
67
+ },
62
68
}
63
69
app .Action = func (c * cli.Context ) error {
64
70
if file == "" {
65
71
cli .ShowAppHelp (c )
66
72
return nil
67
73
}
68
74
69
- var i impl
70
- i = impl {fmt : & tableFormatter {
75
+ var formatter formatter = & tableFormatter {
71
76
noValues : noValues ,
72
- }}
77
+ }
78
+ if useMore {
79
+ formatter = & moreWrapFormatter {
80
+ formatter : formatter ,
81
+ }
82
+ }
83
+
84
+ var i impl
85
+ i = impl {fmt : formatter }
73
86
if _ , err := os .Stat (file ); os .IsNotExist (err ) {
74
87
log .Fatal (err )
75
88
return err
@@ -111,8 +124,8 @@ func (i *impl) readInput() {
111
124
}
112
125
113
126
type formatter interface {
114
- DumpBuckets ([]bucket )
115
- DumpBucketItems (string , []item )
127
+ DumpBuckets (io. Writer , []bucket )
128
+ DumpBucketItems (io. Writer , string , []item )
116
129
}
117
130
118
131
type impl struct {
@@ -203,7 +216,7 @@ func (i *impl) listBucketItems(bucket string, goBack bool) {
203
216
items = append (items , item {Key : string (k ), Value : string (v )})
204
217
}
205
218
fmt .Fprintf (os .Stdout , "Bucket: %s\n " , bucket )
206
- i .fmt .DumpBucketItems (i .bucket , items )
219
+ i .fmt .DumpBucketItems (os . Stdout , i .bucket , items )
207
220
i .root = false // success this far means we're not at ROOT
208
221
i .cache = getQuery // so we can also set the query cache for paging
209
222
outputInstructionline ()
@@ -225,39 +238,10 @@ func (i *impl) listBuckets() {
225
238
}
226
239
227
240
fmt .Fprint (os .Stdout , "DB Layout:\n \n " )
228
- i .fmt .DumpBuckets (buckets )
241
+ i .fmt .DumpBuckets (os . Stdout , buckets )
229
242
outputInstructionline ()
230
243
}
231
244
232
245
func outputInstructionline () {
233
246
fmt .Fprintf (os .Stdout , "\n %s\n \n " , instructionLine )
234
247
}
235
-
236
- type tableFormatter struct {
237
- noValues bool
238
- }
239
-
240
- func (tf tableFormatter ) DumpBuckets (buckets []bucket ) {
241
- table := tablewriter .NewWriter (os .Stdout )
242
- table .SetHeader ([]string {"Buckets" })
243
- for _ , b := range buckets {
244
- row := []string {b .Name }
245
- table .Append (row )
246
- }
247
- table .Render ()
248
- }
249
-
250
- func (tf tableFormatter ) DumpBucketItems (bucket string , items []item ) {
251
- table := tablewriter .NewWriter (os .Stdout )
252
- table .SetHeader ([]string {"Key" , "Value" })
253
- for _ , item := range items {
254
- var row []string
255
- if tf .noValues {
256
- row = []string {item .Key , "" }
257
- } else {
258
- row = []string {item .Key , item .Value }
259
- }
260
- table .Append (row )
261
- }
262
- table .Render ()
263
- }
0 commit comments