Merge pull request #261 from pmezard/improve-bleve-dump
bleve_dump: improve online help and error handling
This commit is contained in:
commit
0ba164322b
|
@ -14,6 +14,8 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/blevesearch/bleve"
|
"github.com/blevesearch/bleve"
|
||||||
_ "github.com/blevesearch/bleve/config"
|
_ "github.com/blevesearch/bleve/config"
|
||||||
|
@ -23,12 +25,23 @@ import (
|
||||||
|
|
||||||
var indexPath = flag.String("index", "", "index path")
|
var indexPath = flag.String("index", "", "index path")
|
||||||
|
|
||||||
var fieldsOnly = flag.Bool("fields", false, "fields only")
|
var fieldsOnly = flag.Bool("fields", false, "print only field definitions")
|
||||||
var docID = flag.String("docID", "", "docID to dump")
|
var docID = flag.String("docID", "", "print only rows related to specified document")
|
||||||
var mappingOnly = flag.Bool("mapping", false, "print mapping")
|
var mappingOnly = flag.Bool("mapping", false, "print only index mappings")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.Usage = func() {
|
||||||
|
fmt.Fprintf(os.Stderr, strings.TrimSpace(`
|
||||||
|
bleve_dump prints the properties and binary representations of all rows in the
|
||||||
|
index specified by -index.
|
||||||
|
`)+"\n\n")
|
||||||
|
flag.PrintDefaults()
|
||||||
|
}
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
if len(flag.Args()) > 0 {
|
||||||
|
log.Fatalf("unexpected argument '%s', use -help to see possible options",
|
||||||
|
flag.Args()[0])
|
||||||
|
}
|
||||||
if *indexPath == "" {
|
if *indexPath == "" {
|
||||||
log.Fatal("specify index to dump")
|
log.Fatal("specify index to dump")
|
||||||
}
|
}
|
||||||
|
@ -45,6 +58,9 @@ func main() {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if *mappingOnly {
|
if *mappingOnly {
|
||||||
|
if *docID != "" || *fieldsOnly {
|
||||||
|
log.Fatal("-mapping cannot be used with -docID or -fields")
|
||||||
|
}
|
||||||
mapping := index.Mapping()
|
mapping := index.Mapping()
|
||||||
jsonBytes, err := json.MarshalIndent(mapping, "", " ")
|
jsonBytes, err := json.MarshalIndent(mapping, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -56,6 +72,9 @@ func main() {
|
||||||
|
|
||||||
var dumpChan chan interface{}
|
var dumpChan chan interface{}
|
||||||
if *docID != "" {
|
if *docID != "" {
|
||||||
|
if *fieldsOnly {
|
||||||
|
log.Fatal("-docID cannot be used with -fields")
|
||||||
|
}
|
||||||
dumpChan = index.DumpDoc(*docID)
|
dumpChan = index.DumpDoc(*docID)
|
||||||
} else if *fieldsOnly {
|
} else if *fieldsOnly {
|
||||||
dumpChan = index.DumpFields()
|
dumpChan = index.DumpFields()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user