-
Notifications
You must be signed in to change notification settings - Fork 384
/
omnisearch.go
57 lines (46 loc) · 1.52 KB
/
omnisearch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"context"
"flag"
"fmt"
"github.com/peterbourgon/ff/v3/ffcli"
"go.uber.org/zap"
"berty.tech/berty/v2/go/internal/initutil"
"berty.tech/berty/v2/go/internal/omnisearch"
)
func omnisearchCommand() *ffcli.Command {
fsBuilder := func() (*flag.FlagSet, error) {
fs := flag.NewFlagSet("berty omnisearch", flag.ExitOnError)
manager.SetupLocalMessengerServerFlags(fs) // we want to configure a local messenger server
manager.SetupDefaultGRPCListenersFlags(fs)
return fs, nil
}
return &ffcli.Command{
Name: "search",
ShortUsage: "berty [global flags] search QUERY",
ShortHelp: "use omnisearch to find information about some things",
LongHelp: `Currently parsers and engines available for omnisearch are :
- Berty invite parser (parse berty's group and one to one invites)
- Berty swiper engine (find peers (peer.AddrInfo) from their invites)
Example:
berty omnisearch https://berty.tech/id#key=CiDnVU4YlFPkjTbSggoZAWbFdAIsnuv5qoruQDyN_NB8rBIgfrT2x0wzMjiK4kBXnPYStGxW2Hssk8UyYfW8ITJbEFg&name=Example`,
Options: ffSubcommandOptions(),
FlagSetBuilder: fsBuilder,
UsageFunc: usageFunc,
Exec: func(ctx context.Context, args []string) error {
if len(args) == 0 {
return flag.ErrHelp
}
manager.Node.Preset = initutil.VolatilePreset
manager.SetLogger(zap.NewNop())
rc, err := omnisearch.DefaultSearch(ctx, manager, args...)
if err != nil {
return err
}
for v := range rc {
fmt.Printf("%s: %#+v\n", v.Finder.Name(), v.Object)
}
return nil
},
}
}